swap Function <functional>
交換兩個 function 物件。
template<class Fty>
void swap(function<Fty>& f1,
function<Fty>& f2);
參數
Fty
函式物件控制項的型別。f1
第一個函式物件。f2
第二個函式物件。
備註
函式會傳回 f1.swap(f2)。
範例
// std_tr1__functional__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;
swap(fn0, 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