swap 関数 <functional>

更新 : 2007 年 11 月

2 つの function オブジェクトを交換します。

template<class Fty>
void swap(function<Fty>& f1,
    function<Fty>& f2);

パラメータ

  • Fty
    XXX

  • f1
    XXX

  • f2
    XXX

解説

この関数は、f1.swap(f2) を返します。

使用例

 

// std_tr1__functional__swap.cpp 
// compile with: /EHsc 
#include <functional> 
#include <iostream> 
 
int neg(int val) 
    { 
    return (-val); 
    } 
 
int main() 
    { 
    std::tr1::function<int (int)> fn0(neg); 
    std::cout << std::boolalpha << "empty == " << !fn0 << std::endl; 
    std::cout << "val == " << fn0(3) << std::endl; 
 
    std::tr1::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); 
    } 
 
empty == false
val == -3
empty == true

empty == true
empty == false
val == -3

必要条件

ヘッダー : <functional>

名前空間 : std::tr1

参照

参照

<functional> (TR1)

function クラス