[expected.void.general] # 22 General utilities library [[utilities]](./#utilities) ## 22.8 Expected objects [[expected]](expected#void.general) ### 22.8.7 Partial specialization of expected for void types [[expected.void]](expected.void#general) #### 22.8.7.1 General [expected.void.general] template requires is_void_vclass expected {public:using [value_type](#lib:expected%3cvoid%3e,value_type "22.8.7.1 General [expected.void.general]") = T; using [error_type](#lib:expected%3cvoid%3e,error_type "22.8.7.1 General [expected.void.general]") = E; using [unexpected_type](#lib:expected%3cvoid%3e,unexpected_type "22.8.7.1 General [expected.void.general]") = unexpected; templateusing [rebind](#lib:expected%3cvoid%3e,rebind "22.8.7.1 General [expected.void.general]") = expected; // [[expected.void.cons]](expected.void.cons "22.8.7.2 Constructors"), constructorsconstexpr expected() noexcept; constexpr expected(const expected&); constexpr expected(expected&&) noexcept(*see below*); templateconstexpr explicit(*see below*) expected(const expected&); templateconstexpr explicit(*see below*) expected(expected&&); templateconstexpr explicit(*see below*) expected(const unexpected&); templateconstexpr explicit(*see below*) expected(unexpected&&); constexpr explicit expected(in_place_t) noexcept; templateconstexpr explicit expected(unexpect_t, Args&&...); templateconstexpr explicit expected(unexpect_t, initializer_list, Args&&...); // [[expected.void.dtor]](expected.void.dtor "22.8.7.3 Destructor"), destructorconstexpr ~expected(); // [[expected.void.assign]](expected.void.assign "22.8.7.4 Assignment"), 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]](expected.void.swap "22.8.7.5 Swap"), swapconstexpr void swap(expected&) noexcept(*see below*); friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))); // [[expected.void.obs]](expected.void.obs "22.8.7.6 Observers"), 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]](expected.void.monadic "22.8.7.7 Monadic operations"), 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]](expected.void.eq "22.8.7.8 Equality operators"), equality operatorstemplate requires is_void_vfriend constexpr bool operator==(const expected& x, const expected& y); templatefriend constexpr bool operator==(const expected&, const unexpected&); private:bool *has_val*; // *exposition only*union { E *unex*; // *exposition only*};}; [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L9513) Any object of type expected either represents a value of type T, or contains a value of type E nested within ([[intro.object]](intro.object "6.8.2 Object model")) it[.](#1.sentence-1) Member *has_val* indicates whether the expected object represents a value of type T[.](#1.sentence-2) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L9521) A program that instantiates the definition of the template expected with a type for the E parameter that is not a valid template argument for unexpected is ill-formed[.](#2.sentence-1) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L9527) E shall meet the requirements of[*Cpp17Destructible*](utility.arg.requirements#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [35](utility.arg.requirements#tab:cpp17.destructible "Table 35: Cpp17Destructible requirements"))[.](#3.sentence-1)