Partager via


function::operator=

Remplace l'objet appelable stockée.

function& operator=(null_ptr_type npc);
function& operator=(const function& right);
template<class Fty>
    function& operator=(Fty fn);
template<class Fty>
    function& operator=(reference_wrapper<Fty> fnref);

Paramètres

  • npc
    Constante de pointeur null.

  • right
    L'objet function à copier.

  • fn
    L'objet appelable à la forme.

  • fnref
    La référence d'objet appelable à la forme.

Notes

Les opérateurs et remplacent l'objet appelable détenu par *this par l'objet passé en tant que appelable opérande.

Exemple

 

// std_tr1__functional__function_operator_as.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; 
    fn1 = 0; 
    std::cout << std::boolalpha << "empty == " << !fn1 << std::endl; 
 
    fn1 = neg; 
    std::cout << std::boolalpha << "empty == " << !fn1 << std::endl; 
    std::cout << "val == " << fn1(3) << std::endl; 
 
    fn1 = fn0; 
    std::cout << std::boolalpha << "empty == " << !fn1 << std::endl; 
    std::cout << "val == " << fn1(3) << std::endl; 
 
    fn1 = std::cref(fn1); 
    std::cout << std::boolalpha << "empty == " << !fn1 << std::endl; 
    std::cout << "val == " << fn1(3) << std::endl; 
 
    return (0); 
    } 
 
  

Configuration requise

En-tête : <functional>

Espace de noms : std

Voir aussi

Référence

function, classe

function::function

function::swap