// 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
処理系
- Clang: 24 ✅
- GCC: 16.1 ❌
- Visual C++: 2026 Update 6 ❌