function::swap
交換兩個可呼叫的物件。
void swap(function& right);
參數
- right
要交換的函式物件。
備註
成員函式切換 *this 和 right的目標物件。 它在常數時間這樣做並不會擲回例外狀況。
範例
// std_tr1__functional__function_swap.cpp
// compile with: /EHsc
#include <functional>
#include <iostream>
int neg(int val)
{
return (-val);
}
int main()
{
std::function<int (int)> fn0(neg);
std::cout << std::boolalpha << "empty == " << !fn0 << std::endl;
std::cout << "val == " << fn0(3) << std::endl;
std::function<int (int)> fn1;
std::cout << std::boolalpha << "empty == " << !fn1 << std::endl;
std::cout << std::endl;
fn0.swap(fn1);
std::cout << std::boolalpha << "empty == " << !fn0 << std::endl;
std::cout << std::boolalpha << "empty == " << !fn1 << std::endl;
std::cout << "val == " << fn1(3) << std::endl;
return (0);
}
需求
標題: <functional>
命名空間: std