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

履歴 編集

function template
<functional>

std::move_only_function::operator!=(C++23)

// operator==により、以下のオーバーロードが使用可能になる
bool operator!=(const move_only_function& f, nullptr_t) noexcept; // (1)

bool operator!=(nullptr_t, const move_only_function& f) noexcept; // (2)

概要

非等値比較する。

戻り値

static_cast<bool>(f)

#include <iostream>
#include <functional>

int ident(int x) { return x; }

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

  if (f != nullptr) {
    std::cout << "not empty" << std::endl;
  }

  f = nullptr;
  if (f != nullptr) {}
  else {
    std::cout << "empty" << std::endl;
  }
}

出力

not empty
empty

バージョン

言語

  • C++23

処理系

参照