Share via


swap Function <functional>

Swaps two function objects.

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

Parameters

  • Fty
    XXX

  • f1
    XXX

  • f2
    XXX

Remarks

The function returns f1.swap(f2).

Example

 

// 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

Requirements

Header: <functional>

Namespace: std::tr1

See Also

Reference

<functional> (TR1)

function Class