cpp/utility/expected/unexpected

The class template represents an unexpected value stored in std. In particular, has constructors with  as a single argument, which creates an  object that contains an unexpected value.

A program is ill-formed if it instantiates an with a non-object type, an array type, a specialization of, or a cv-qualified type.

Non-member functions
{{member|1={{small|std::unexpected::}}unexpected|2= {{dcl begin}} {{dcl|num=1|since=c++23|1= constexpr unexpected( const unexpected& ) = default; }} {{dcl|num=2|since=c++23|1= constexpr unexpected( unexpected&& ) = default; }} {{dcl|num=3|since=c++23|1= template< class Err = E > constexpr explicit unexpected( Err&& e ); }} {{dcl|num=4|since=c++23|1= template< class... Args > constexpr explicit unexpected( std::in_place_t, Args&&... args ); }} {{dcl|num=5|since=c++23|1= template< class U, class... Args > constexpr explicit unexpected( std::in_place_t,                              std::initializer_list il, Args&&... args ); }} {{dcl end}}

Constructs a {{tt|std::unexpected}} object.

@1,2@ Copy/move constructor. Copies or moves the stored value, respectively. @3@ Constructs the stored value, as if by direct-initializing a value of type {{tt|E}} from {{c|std::forward(e)}}. }} @4@ Constructs the stored value, as if by direct-initializing a value of type {{tt|E}} from the arguments {{c|std::forward(args)...}}. @5@ Constructs the stored value, as if by direct-initializing a value of type {{tt|E}} from the arguments {{c|il, std::forward(args)...}}.
 * {{cpp/enable_if|
 * {{c|std::is_same_v, unexpected>}} is false, and
 * {{c|std::is_same_v, std::in_place_t>}} is false, and
 * {{c|std::is_constructible_v}} is true.
 * {{cpp/enable_if|{{c|std::is_constructible_v}} is true.}}
 * {{cpp/enable_if|{{c|std::is_constructible_v&, Args...>}} is true.}}

Exceptions
Throws any exception thrown by the constructor of. }}

Deduction guides
The deduction guide is provided for unexpected to allow deduction from the constructor argument.