A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/functional/function/operator_bool/ below:

public member function

<functional>

std::function::operator bool
explicit operator bool() const noexcept;

Check if callable

Returns whether the object is callable.

A function object is callable if it is not an empty function (i.e., if it has a callable object as target).



Parameters none

Return valuetrue if the object is callable.
false otherwise (the object is an empty function).

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// function::operator bool example
#include <iostream>     // std::cout
#include <functional>   // std::function, std::plus

int main () {
  std::function<int(int,int)> foo,bar;
  foo = std::plus<int>();

  foo.swap(bar);

  std::cout << "foo is " << (foo ? "callable" : "not callable") << ".\n";
  std::cout << "bar is " << (bar ? "callable" : "not callable") << ".\n";

  return 0;
}

Output:
foo is not callable.
bar is callable.


Data races The object is accessed.

Exception safetyNo-throw guarantee: this member function never throws exceptions.

See also
function::target
Get pointer to target (public member function)
function::operator()
Call target (public member function)

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