Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

function::operator=

Replaces the stored callable object.

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

npc

A null pointer constant.

right

The function object to copy.

fn

The callable object to wrap.

fnref

The callable object reference to wrap.

The operators each replace the callable object held by *this with the callable object passed as the operand.

 

// 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); 
    } 
 
empty == false
val == -3
empty == true
empty == false
val == -3
empty == false
val == -3
empty == false
val == -3

Header: <functional>

Namespace: std

Show:
© 2014 Microsoft