最終更新日時(UTC):
が更新

履歴 編集

function
<functional>

std::move_only_function::operator bool(C++23)

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

処理系

参照