다음을 통해 공유


swap 함수 <functional>

두 function 개체를 바꿉니다.

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

매개 변수

  • Fty
    The type controlled by the function objects.

  • f1
    The first function object.

  • f2
    The second function object.

설명

함수는 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); 
    } 
 
  

요구 사항

헤더: <기능>

네임스페이스: std

참고 항목

참조

function 클래스