Skip to content

Glossary: C++ Beyond the Basics

std::expected

Also written: expected, std::unexpected, expected<T, E>

A C++23 type holding either a value `T` or an error `E`, so the caller learns why something failed. Return success as a `T` and failure as `std::unexpected(error)`.

Where the book teaches it

Related terms

std::optionalScoped enumerationand_thentransform (std::expected)