This header is part of thegeneral utility library.
Classes | ||
(C++23) | a wrapper that contains either an expected or error value (class template)[edit] | |
(C++23) | represented as an unexpected value (class template)[edit] | |
(C++23) | exception indicating checked access to anexpected that contains an unexpected value(class template)[edit] | |
(C++23) | in-place construction tag for unexpected value inexpected (tag)[edit] |
// mostly freestandingnamespace std{// class template unexpectedtemplate<class E>class unexpected; // class template bad_expected_accesstemplate<class E>class bad_expected_access; // specialization for voidtemplate<>class bad_expected_access<void>; // in-place construction of unexpected valuesstruct unexpect_t{explicit unexpect_t()=default;};inlineconstexpr unexpect_t unexpect{}; // class template expectedtemplate<class T,class E>class expected;// partially freestanding // partial specialization of expected for void typestemplate<class T,class E> requires is_void_v<T>class expected<T, E>;// partially freestanding}
namespace std{template<class E>class unexpected{public:// constructorsconstexpr unexpected(const unexpected&)=default;constexpr unexpected(unexpected&&)=default;template<class Err= E>constexprexplicit unexpected(Err&&);template<class...Args>constexprexplicit unexpected(in_place_t, Args&&...);template<class U,class...Args>constexprexplicit unexpected(in_place_t, initializer_list<U>, Args&&...); constexpr unexpected& operator=(const unexpected&)=default;constexpr unexpected& operator=(unexpected&&)=default; constexprconst E& error()const&noexcept;constexpr E& error()&noexcept;constexprconst E&& error()const&&noexcept;constexpr E&& error()&&noexcept; constexprvoid swap(unexpected& other)noexcept(/* see description */); template<class E2>friendconstexprbool operator==(const unexpected&,const unexpected<E2>&); friendconstexprvoid swap(unexpected& x, unexpected& y)noexcept(noexcept(x.swap(y))); private: E/*unex*/;// exposition-only}; template<class E> unexpected(E)-> unexpected<E>;}
namespace std{template<class E>class bad_expected_access:public bad_expected_access<void>{public:constexprexplicit bad_expected_access(E);constexprconstchar* what()constnoexcept override;constexpr E& error()&noexcept;constexprconst E& error()const&noexcept;constexpr E&& error()&&noexcept;constexprconst E&& error()const&&noexcept; private: E/*unex*/;// exposition-only};}
namespace std{template<>class bad_expected_access<void>:public exception{protected:constexpr bad_expected_access()noexcept;constexpr bad_expected_access(const bad_expected_access&)noexcept;constexpr bad_expected_access(bad_expected_access&&)noexcept;constexpr bad_expected_access& operator=(const bad_expected_access&)noexcept;constexpr bad_expected_access& operator=(bad_expected_access&&)noexcept;constexpr ~bad_expected_access(); public:constexprconstchar* what()constnoexcept override;};}
namespace std{template<class T,class E>class expected{public:using value_type= T;using error_type= E;using unexpected_type= unexpected<E>; template<class U>using rebind= expected<U, error_type>; // constructorsconstexpr expected();constexpr expected(const expected&);constexpr expected(expected&&)noexcept(/* see description */);template<class U,class G>constexprexplicit(/* see description */) expected(const expected<U, G>&);template<class U,class G>constexprexplicit(/* see description */) expected(expected<U, G>&&); template<class U= remove_cv_t<T>>constexprexplicit(/* see description */) expected(U&& v); template<class G>constexprexplicit(/* see description */) expected(const unexpected<G>&);template<class G>constexprexplicit(/* see description */) expected(unexpected<G>&&); template<class...Args>constexprexplicit expected(in_place_t, Args&&...);template<class U,class...Args>constexprexplicit expected(in_place_t, initializer_list<U>, Args&&...);template<class...Args>constexprexplicit expected(unexpect_t, Args&&...);template<class U,class...Args>constexprexplicit expected(unexpect_t, initializer_list<U>, Args&&...); // destructorconstexpr ~expected(); // assignmentconstexpr expected& operator=(const expected&);constexpr expected& operator=(expected&&)noexcept(/* see description */);template<class U= remove_cv_t<T>>constexpr expected& operator=(U&&);template<class G>constexpr expected& operator=(const unexpected<G>&);template<class G>constexpr expected& operator=(unexpected<G>&&); template<class...Args>constexpr T& emplace(Args&&...)noexcept;template<class U,class...Args>constexpr T& emplace(initializer_list<U>, Args&&...)noexcept; // swapconstexprvoid swap(expected&)noexcept(/* see description */);friendconstexprvoid swap(expected& x, expected& y)noexcept(noexcept(x.swap(y))); // observersconstexprconst T* operator->()constnoexcept;constexpr T* operator->()noexcept;constexprconst T& operator*()const&noexcept;constexpr T& operator*()&noexcept;constexprconst T&& operator*()const&&noexcept;constexpr T&& operator*()&&noexcept;constexprexplicit operatorbool()constnoexcept;constexprbool has_value()constnoexcept;constexprconst T& value()const&;// freestanding-deletedconstexpr T& value()&;// freestanding-deletedconstexprconst T&& value()const&&;// freestanding-deletedconstexpr T&& value()&&;// freestanding-deletedconstexprconst E& error()const&noexcept;constexpr E& error()&noexcept;constexprconst E&& error()const&&noexcept;constexpr E&& error()&&noexcept;template<class U= remove_cv_t<T>>constexpr T value_or(U&&)const&;template<class U= remove_cv_t<T>>constexpr T value_or(U&&)&&;template<class G= E>constexpr E error_or(G&&)const&;template<class G= E>constexpr E error_or(G&&)&&; // monadic operationstemplate<class F>constexprauto and_then(F&& f)&;template<class F>constexprauto and_then(F&& f)&&;template<class F>constexprauto and_then(F&& f)const&;template<class F>constexprauto and_then(F&& f)const&&;template<class F>constexprauto or_else(F&& f)&;template<class F>constexprauto or_else(F&& f)&&;template<class F>constexprauto or_else(F&& f)const&;template<class F>constexprauto or_else(F&& f)const&&;template<class F>constexprauto transform(F&& f)&;template<class F>constexprauto transform(F&& f)&&;template<class F>constexprauto transform(F&& f)const&;template<class F>constexprauto transform(F&& f)const&&;template<class F>constexprauto transform_error(F&& f)&;template<class F>constexprauto transform_error(F&& f)&&;template<class F>constexprauto transform_error(F&& f)const&;template<class F>constexprauto transform_error(F&& f)const&&; // equality operatorstemplate<class T2,class E2> requires(!is_void_v<T2>)friendconstexprbool operator==(const expected& x,const expected<T2, E2>& y);template<class T2>friendconstexprbool operator==(const expected&,const T2&);template<class E2>friendconstexprbool operator==(const expected&,const unexpected<E2>&); private:bool/*has-val*/;// exposition-onlyunion{ T/*val*/;// exposition-only E/*unex*/;// exposition-only};};}
template<class T,class E> requires is_void_v<T>class expected<T, E>{public:using value_type= T;using error_type= E;using unexpected_type= unexpected<E>; template<class U>using rebind= expected<U, error_type>; // constructorsconstexpr expected()noexcept;constexpr expected(const expected&);constexpr expected(expected&&)noexcept(/* see description */);template<class U,class G>constexprexplicit(/* see description */) expected(const expected<U, G>&);template<class U,class G>constexprexplicit(/* see description */) expected(expected<U, G>&&); template<class G>constexprexplicit(/* see description */) expected(const unexpected<G>&);template<class G>constexprexplicit(/* see description */) expected(unexpected<G>&&); constexprexplicit expected(in_place_t)noexcept;template<class...Args>constexprexplicit expected(unexpect_t, Args&&...);template<class U,class...Args>constexprexplicit expected(unexpect_t, initializer_list<U>, Args&&...); // destructorconstexpr ~expected(); // assignmentconstexpr expected& operator=(const expected&);constexpr expected& operator=(expected&&)noexcept(/* see description */);template<class G>constexpr expected& operator=(const unexpected<G>&);template<class G>constexpr expected& operator=(unexpected<G>&&);constexprvoid emplace()noexcept; // swapconstexprvoid swap(expected&)noexcept(/* see description */);friendconstexprvoid swap(expected& x, expected& y)noexcept(noexcept(x.swap(y))); // observersconstexprexplicit operatorbool()constnoexcept;constexprbool has_value()constnoexcept;constexprvoid operator*()constnoexcept;constexprvoid value()const&;// freestanding-deletedconstexprvoid value()&&;// freestanding-deletedconstexprconst E& error()const&noexcept;constexpr E& error()&noexcept;constexprconst E&& error()const&&noexcept;constexpr E&& error()&&noexcept;template<class G= E>constexpr E error_or(G&&)const&;template<class G= E>constexpr E error_or(G&&)&&; // monadic operationstemplate<class F>constexprauto and_then(F&& f)&;template<class F>constexprauto and_then(F&& f)&&;template<class F>constexprauto and_then(F&& f)const&;template<class F>constexprauto and_then(F&& f)const&&;template<class F>constexprauto or_else(F&& f)&;template<class F>constexprauto or_else(F&& f)&&;template<class F>constexprauto or_else(F&& f)const&;template<class F>constexprauto or_else(F&& f)const&&;template<class F>constexprauto transform(F&& f)&;template<class F>constexprauto transform(F&& f)&&;template<class F>constexprauto transform(F&& f)const&;template<class F>constexprauto transform(F&& f)const&&;template<class F>constexprauto transform_error(F&& f)&;template<class F>constexprauto transform_error(F&& f)&&;template<class F>constexprauto transform_error(F&& f)const&;template<class F>constexprauto transform_error(F&& f)const&&; // equality operatorstemplate<class T2,class E2> requires is_void_v<T2>friendconstexprbool operator==(const expected& x,const expected<T2, E2>& y);template<class E2>friendconstexprbool operator==(const expected&,const unexpected<E2>&); private:bool/*has-val*/;// exposition-onlyunion{ E/*unex*/;// exposition-only};};