Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

function::operator bool

公共成员函数  <functional>

explicit operator bool() const noexcept;

检查是否可调用
返回对象是否可调用。

如果函数对象不是空函数(也就是说,如果它有一个可调用对象作为 target),那么它就是可调用的。

☲  参数


none

☉  返回值



如果对象是可调用的,则为True。 否则为False(对象为空函数)。

☣  示例



// 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.

⇄ 数据竞争



对象被访问。

☂ 异常安全性



无抛出保证:该成员函数从不抛出异常。

🍄  另请参阅



function::operator() 调用目标对象(公共成员函数)
function::target 获取指向目标的指针(公共成员函数)

联系我们 免责声明 关于CandCplus 网站地图