A RetroSearch Logo

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

Search Query:

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

function template

<functional>

std::relational operators (function) (1)
template <class Ret, class... Args>  bool operator== (const function<Ret(Args...)>& lhs, nullptr_t rhs) noexcept;template <class Ret, class... Args>  bool operator== (nullptr_t lhs, const function<Ret(Args...)>& rhs) noexcept;
(2)
template <class Ret, class... Args>  bool operator!= (const function<Ret(Args...)>& lhs, nullptr_t rhs) noexcept;template <class Ret, class... Args>  bool operator!= (nullptr_t lhs, const function<Ret(Args...)>& rhs) noexcept;

Relational operators for function vs null pointer

Performs the appropriate comparison against null pointers:

equality comparison (1)
Returns true if the function object is an empty function (i.e., it has no target).
inequality comparison (2)
Returns true if the function object is not an empty function (i.e., it has a target).


Note that two function objects cannot be compared directly using these operators.

Parameters
lhs, rhs
A function object and a null pointer, in either order.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
// function comparisons vs nullptr
#include <iostream>     // std::cout
#include <functional>   // std::function, std::plus

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

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

  return 0;
}

Output:
foo is callable
bar is not callable


Return Valuetrue if the condition holds, and false otherwise.

Data races The function object involved is accessed.

Exception safetyNo-throw guarantee: never throws exceptions.

See also
function::operator bool
Check if callable (public member function)
function::target_type
Target type_info (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