5.3 KiB
[expected.void.general]
22 General utilities library [utilities]
22.8 Expected objects [expected]
22.8.7 Partial specialization of expected for void types [expected.void]
22.8.7.1 General [expected.void.general]
template<class T, class E> requires is_void_vclass expected<T, E> {public:using value_type = T; using error_type = E; using unexpected_type = unexpected; templateusing rebind = expected<U, error_type>; // [expected.void.cons], constructorsconstexpr expected() noexcept; constexpr expected(const expected&); constexpr expected(expected&&) noexcept(see below); template<class U, class G>constexpr explicit(see below) expected(const expected<U, G>&); template<class U, class G>constexpr explicit(see below) expected(expected<U, G>&&); templateconstexpr explicit(see below) expected(const unexpected&); templateconstexpr explicit(see below) expected(unexpected&&); constexpr explicit expected(in_place_t) noexcept; template<class... Args>constexpr explicit expected(unexpect_t, Args&&...); template<class U, class... Args>constexpr explicit expected(unexpect_t, initializer_list, Args&&...); // [expected.void.dtor], destructorconstexpr ~expected(); // [expected.void.assign], assignmentconstexpr expected& operator=(const expected&); constexpr expected& operator=(expected&&) noexcept(see below); templateconstexpr expected& operator=(const unexpected&); templateconstexpr expected& operator=(unexpected&&); constexpr void emplace() noexcept; // [expected.void.swap], swapconstexpr void swap(expected&) noexcept(see below); friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))); // [expected.void.obs], observersconstexpr explicit operator bool() const noexcept; constexpr bool has_value() const noexcept; constexpr void operator*() const noexcept; constexpr void value() const &; // freestanding-deletedconstexpr void value() &&; // freestanding-deletedconstexpr const E& error() const & noexcept; constexpr E& error() & noexcept; constexpr const E&& error() const && noexcept; constexpr E&& error() && noexcept; template constexpr E error_or(G&&) const &; template constexpr E error_or(G&&) &&; // [expected.void.monadic], monadic operationstemplate constexpr auto and_then(F&& f) &; template constexpr auto and_then(F&& f) &&; template constexpr auto and_then(F&& f) const &; template constexpr auto and_then(F&& f) const &&; template constexpr auto or_else(F&& f) &; template constexpr auto or_else(F&& f) &&; template constexpr auto or_else(F&& f) const &; template constexpr auto or_else(F&& f) const &&; template constexpr auto transform(F&& f) &; template constexpr auto transform(F&& f) &&; template constexpr auto transform(F&& f) const &; template constexpr auto transform(F&& f) const &&; template constexpr auto transform_error(F&& f) &; template constexpr auto transform_error(F&& f) &&; template constexpr auto transform_error(F&& f) const &; template constexpr auto transform_error(F&& f) const &&; // [expected.void.eq], equality operatorstemplate<class T2, class E2> requires is_void_vfriend constexpr bool operator==(const expected& x, const expected<T2, E2>& y); templatefriend constexpr bool operator==(const expected&, const unexpected&);
private:bool has_val; // exposition onlyunion { E unex; // exposition only};};
Any object of type expected<T, E> either represents a value of type T, or contains a value of type E nested within ([intro.object]) it.
Member has_val indicates whether the expected<T, E> object represents a value of type T.
A program that instantiates the definition of the template expected<T, E> with a type for the E parameter that is not a valid template argument for unexpected is ill-formed.
E shall meet the requirements ofCpp17Destructible (Table 35).