Udostępnij za pośrednictwem


function::swap

Zamiana dwóch obiektów wpłacone.

void swap(function& right);

Parametry

  • right
    Obiekt funkcji wymiany.

Uwagi

Funkcja Członkowskie zamienia obiektów docelowych między *this i right.Nie tak w czasie stałą i wygeneruje żadnych wyjątków.

Przykład

 

// 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); 
    } 
 
  

Wymagania

Nagłówek: <functional>

Obszar nazw: std

Zobacz też

Informacje

function Class

function::operator=