Unexpected Nip Slip

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

unexpected nip slip 1 Exclusive Content Member Only — Sign Up Free 🔒 Unlock full images & premium access

Represents an expected void value or contains an unexpected value. If it contains an unexpected value, it is nested within the expected object. A program is ill-formed if it instantiates an expected with a reference type, a function type, or a specialization of std::unexpected. In addition, T must not be std::in_place_t or std::unexpect_t.

unexpected nip slip 2 Exclusive Content Member Only — Sign Up Free 🔒 Unlock full images & premium access
1Classes 2Synopsis 2.1Class template std::unexpected 2.2Class template std::bad_expected_access 2.3Class template specialization std::bad_expected_access 2.4Class template std::expected 2.5Partial specialization of std::expected for void types std::remove_cvref_t is not a specialization of std::unexpected. If T is (possibly cv-qualified) bool, std::remove_cvref_t is not a specialization of std::expected.
unexpected nip slip 4 Exclusive Content Member Only — Sign Up Free 🔒 Unlock full images & premium access
  1. A tag type for in-place construction of an unexpected value in an std::expected object. 2) A constant of type const std::unexpect_t which is usually directly passed to a constructor of std::expected to construct an unexpected value.

Return value The previously-installed unexpected handler, or a null pointer value if none was installed.

unexpected nip slip 6 Exclusive Content Member Only — Sign Up Free 🔒 Unlock full images & premium access

std::unexpected_handler is the function pointer type (pointer to function that takes no arguments and returns void), which is installed and queried by the functions std::set_unexpected and std::get_unexpected and called by std::unexpected. The C++ implementation provides a default std::unexpected_handler function, which calls std::terminate ().

unexpected nip slip 7 Exclusive Content Member Only — Sign Up Free 🔒 Unlock full images & premium access

If *this represents an expected value, invokes f and returns a std::expected object that contains an expected value, which is initialized with its result (or value-initialized if the result type is void). Otherwise, returns a std::expected object that contains an unexpected value, which is initialized with the unexpected value of *this.