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.

引數

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

示例

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;
}

輸出
foo is callable
bar is not callable


返回值

如果條件成立,則為 true;否則為 false

資料競爭

The function object involved is accessed.

異常安全

無異常保證: 絕不丟擲異常。

另見