- expected[meta header]
- function[meta id-type]
- std[meta namespace]
- expected.void[meta class]
- cpp23[meta cpp]
// expected<cv void, E>部分特殊化
constexpr void value() const &; // (1)
constexpr void value() &&; // (2)
正常値(void
)を取得する。
なし
- (1) : エラー値を保持していたら、例外
bad_expected_access
(
error()
)
をスローする - (2) : エラー値を保持していたら、例外
bad_expected_access
(
std::move
(
error()
))
をスローする
#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;
}
}
- value()[color ff0000]
- error()[link ../bad_expected_access/error.md]
- std::unexpected[link ../unexpected.md]
- std::bad_expected_access[link ../bad_expected_access.md]
throw:42
- C++23
- Clang: 16.0 [mark verified]
- GCC: 12.1 [mark verified]
- ICC: ??
- Visual C++: ??