Export (0) Print
Expand All

function::operator unspecified

Tests if stored callable object exists.

operator unspecified();

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.

 

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

Header: <functional>

Namespace: std

Show:
© 2014 Microsoft