public member function
<functional>

std::function::operator bool

explicit operator bool() const noexcept;
檢查是否可呼叫
返回物件是否可呼叫。

如果 function 物件是可呼叫的(即,其 target 是一個 *可呼叫物件*),則為真。

引數



返回值

如果物件可呼叫,則為 true
否則(物件是 *空函式*)為 false

示例

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

輸出
foo is not callable.
bar is callable.


資料競爭

該物件被訪問。

異常安全

無異常保證:此成員函式從不丟擲異常。

另見