最終更新日時:
が更新

履歴 編集

function
<expected>

std::expected.void::has_error(C++29)

// expected<cv void, E>部分特殊化
constexpr bool has_error() const noexcept;

概要

エラー値を保持しているかを判定する。

効果

以下と等価である。

return !has_value();

例外

投げない

備考

  • expected<cv void, E>部分特殊化は正常「値」を持たないため、has_value()の否定よりも意図が読み取りやすくなる

#include <expected>
#include <iostream>

int main()
{
  std::expected<void, int> x;
  std::cout << x.has_error() << std::endl;

  std::expected<void, int> y = std::unexpected{42};
  std::cout << y.has_error() << std::endl;
}

出力

0
1

バージョン

言語

  • C++29

処理系

関連項目

参照