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

履歴 編集

function
<expected>

std::expected.void::value(C++23)

// expected<cv void, E>部分特殊化
constexpr void value() const &; // (1)
constexpr void value() &&;      // (2)

概要

正常値(void)を取得する。

戻り値

なし

例外

#include <expected>
#include <iostream>

int main()
{
  std::expected<void, int> x;
  x.value();

  std::expected<void, int> y = std::unexpected{42};
  try {
    y.value();
  } catch (const std::bad_expected_access<int>& ex) {
    std::cout << "throw:" << ex.error() << std::endl;
  }
}

出力

throw:42

バージョン

言語

  • C++23

処理系

関連項目

参照