Header Reference: <expected>
Header Reference: <expected>
The value-or-error result type std::expected and the main patterns it supports in modern C++ APIs.
Header Reference: <expected>
The value-or-error result type std::expected and the main patterns it supports in modern C++ APIs.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
Header reference pages are meant to answer a practical question quickly: what this header provides, when to reach for it, and which usage rules are easiest to get wrong.
<expected>std::expected<T, E>std::unexpected<E>std::bad_expected_access<E>std::optional#include <expected>
#include <string>
std::expected<int, std::string> parse(bool ok) {
if (!ok) {
return std::unexpected("parse failure");
}
return 42;
}