template <class Ret, class... Args> void swap (function<Ret(Args...)>& x, function<Ret(Args...)>& y); |
// swapping functions
#include <iostream> // std::cout
#include <functional> // std::function, std::plus
int main () {
std::function<int(int,int)> foo,bar;
foo = std::plus<int>();
swap(foo,bar);
std::cout << "foo is " << (foo ? "callable" : "not callable") << ".\n";
std::cout << "bar is " << (bar ? "callable" : "not callable") << ".\n";
return 0;
}
|
| swap | 交换两个对象的值(函数模板) |
| function::swap | 交换目标(公共成员函数) |
| function::assign | 赋值目标并分配空间(公共成员函数) |