- expected[meta header]
- function[meta id-type]
- std[meta namespace]
- expected.void[meta class]
- cpp29[meta cpp]
// expected<cv void, E>部分特殊化
constexpr bool has_error() const noexcept;エラー値を保持しているかを判定する。
以下と等価である。
return !has_value();- has_value()[link has_value.md]
投げない
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;
}- has_error[color ff0000]
- std::unexpected[link ../unexpected.md]
0
1
- C++29
- Clang: 24 [mark verified]
- GCC: 16.1 [mark noimpl]
- Visual C++: 2026 Update 6 [mark noimpl]