It is used to check if a valid target is contained.
DeclarationFollowing is the declaration for std::function::function::operator bool.
explicit operator bool() const;C++11
explicit operator bool() const;Parameters
none
Return ValueIt returns true if *this stores a callable function target, false otherwise.
Exceptionsnoexcept: It doesnot throw any exceptions.
ExampleIn below example for std::function::operator bool.
#include <functional> #include <iostream> void sampleFunction() { std::cout << "This is the sample example of function!\n"; } void checkFunc( std::function<void()> &func ) { if( func ) { std::cout << "Function is not empty! It is a calling function.\n"; func(); } else { std::cout << "Function is empty.\n"; } } int main() { std::function<void()> f1; std::function<void()> f2( sampleFunction ); std::cout << "f1: "; checkFunc( f1 ); std::cout << "f2: "; checkFunc( f2 ); }
The output should be like this −
f1: Function is empty. f2: Function is not empty! It is a calling function. This is the sample example of function!
functional.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4