function::operator unspecified

Tests if stored callable object exists.

operator unspecified();

Remarks

The operator returns a value that is convertible to bool with a true value only if the object is not empty. You use it to test whether the object is empty.

Example

 

// std_tr1__functional__function_operator_bool.cpp 
// compile with: /EHsc 
#include <functional> 
#include <iostream> 
 
int neg(int val) 
    { 
    return (-val); 
    } 
 
int main() 
    { 
    std::tr1::function<int (int)> fn0; 
    std::cout << std::boolalpha << "not empty == " << (bool)fn0 << std::endl; 
 
    std::tr1::function<int (int)> fn1(neg); 
    std::cout << std::boolalpha << "not empty == " << (bool)fn1 << std::endl; 
 
    return (0); 
    } 
 

not empty == false not empty == true

Requirements

Header: <functional>

Namespace: std::tr1

See Also

Reference

<functional> (TR1)

function Class

bad_function_call Class