Skip to content

Latest commit

 

History

History
58 lines (43 loc) · 988 Bytes

File metadata and controls

58 lines (43 loc) · 988 Bytes

operator bool

  • functional[meta header]
  • std[meta namespace]
  • move_only_function[meta class]
  • function[meta id-type]
  • cpp23[meta cpp]
explicit operator bool() const noexcept;

概要

関数呼び出しが可能か調べる。

戻り値

呼び出す関数を持っていればtrue、そうでなければfalseを返す。

#include <iostream>
#include <functional>

int ident(int x) { return x; }

int main()
{
  std::move_only_function<int(int)> f = ident;

  if (f) {
    std::cout << "not empty" << std::endl;
  }
  else {
    std::cout << "empty" << std::endl;
  }
}

出力

not empty

バージョン

言語

  • C++23

処理系

参照