diff --git a/Makefile b/Makefile index 37294ba..86ad863 100755 --- a/Makefile +++ b/Makefile @@ -261,6 +261,25 @@ wording-check: ## Check the checked-in wording matches what the headers generate diff $(WORDING_DIR)/fragments/$$fragment $(BUILD_DIR)/wording-check/fragments/$$fragment || exit 1; \ done +# Deletes everything specgen and the assembly wrote, so that the next `make +# wording` writes all of it again. This is for a change in specgen itself: the +# rules above compare the wording with the headers, a new specgen changes the +# output without touching one, and so make sees nothing to do. `make -B +# wording` is no substitute, because .DEFAULT below then hands every +# prerequisite that has no rule of its own, the headers and this makefile among +# them, to cmake as a target. +# +# The fragments and expected.tex are checked in. So this refuses to run when +# there is no specgen to put them back, and neither clean nor realclean +# depends on it. +.PHONY: clean-wording +clean-wording: ## Delete the generated wording, so that 'make wording' regenerates all of it + @command -v $(SPECGEN) > /dev/null 2>&1 || { \ + echo "error: '$(SPECGEN)' not found; nothing could regenerate the checked-in wording" >&2; \ + exit 1; } + rm -f $(WORDING_DIR)/expected.tex $(WORDING_FRAGMENTS) \ + $(WORDING_DIR)/fragments/*.root.tex papers/.deps/wording.d + # What specgen read to produce the fragments -- including headers reached only # through an #include, which is the edge a hand-written prerequisite list # forgets. Written by --depfile above; absent until the first run, hence diff --git a/papers/wording/README.md b/papers/wording/README.md index 0706e00..6d65ec5 100644 --- a/papers/wording/README.md +++ b/papers/wording/README.md @@ -16,6 +16,17 @@ has real prerequisites, so it does nothing when nothing changed, and `make papers` regenerates the wording before building the PDF — a paper can no longer be built from stale clauses. +Those prerequisites are the headers, so a new specgen that renders the same +headers differently leaves make with nothing to do. For that case: + +```sh +make clean-wording wording +``` + +`clean-wording` deletes the fragments, `expected.tex`, and the depfile, and +`wording` writes them all again. It deletes checked-in files, so it refuses to +run when `specgen` is not found, and `make clean` does not reach it. + GNU Make 4.3 or newer. One specgen invocation writes all six fragments, which the makefile states as a grouped target (`&:`) — a rule 4.2 parses as something else entirely, and would then run specgen once per fragment. diff --git a/papers/wording/expected.tex b/papers/wording/expected.tex index 2d42b68..dfa1a88 100644 --- a/papers/wording/expected.tex +++ b/papers/wording/expected.tex @@ -25,24 +25,18 @@ namespace std { template class @\libglobal{unexpected}@ { - // [expected.un.general] para 2: ill-formed instantiations - public: constexpr unexpected(const unexpected&) = default; constexpr unexpected(unexpected&&) = default; template - requires(!is_same_v, unexpected> && - !is_same_v, in_place_t> && is_constructible_v) constexpr explicit unexpected(Err&& e) noexcept(is_nothrow_constructible_v); template - requires is_constructible_v constexpr explicit unexpected(in_place_t, Args&&... args) noexcept( is_nothrow_constructible_v); template - requires is_constructible_v&, Args...> constexpr explicit unexpected( in_place_t, initializer_list il, Args&&... args) noexcept(is_nothrow_constructible_v&, @@ -61,8 +55,8 @@ template friend constexpr bool operator==(const unexpected& x, const unexpected& y); - friend constexpr void swap(unexpected& x, unexpected& y) noexcept(noexcept(x.swap(y))) - requires is_swappable_v; + friend constexpr void swap(unexpected& x, + unexpected& y) noexcept(noexcept(x.swap(y))); private: E @\exposidnc{unex}@; // exposition only @@ -70,7 +64,6 @@ } \end{codeblock} -\begin{itemdescr} \pnum \mandates A program that instantiates the definition of \tcode{unexpected} for a non-object type other than an lvalue reference type, an array type, a specialization of \tcode{unexpected}, or a cv-qualified type is ill-formed. @@ -78,14 +71,13 @@ \pnum \remarks Subclause \iref{expected.unexpected} describes the class template \tcode{unexpected} that represents unexpected objects stored in \tcode{expected} objects. -\end{itemdescr} \rSec3[expected.un.cons]{Constructors} \indexlibraryctor{unexpected}% \begin{itemdecl} template -constexpr explicit unexpected(Err&& e) noexcept(is_nothrow_constructible_v); + constexpr explicit unexpected(Err&& e) noexcept(is_nothrow_constructible_v); \end{itemdecl} \begin{itemdescr} @@ -99,18 +91,17 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(e)}. +Direct-non-list-initializes \exposid{unex} with \tcode{std::forward(e)}. \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{unexpected}% \begin{itemdecl} template -constexpr explicit unexpected(in_place_t, Args&&... args) noexcept( - is_nothrow_constructible_v); + constexpr explicit unexpected(in_place_t, Args&&... args) noexcept(is_nothrow_constructible_v); \end{itemdecl} \begin{itemdescr} @@ -120,34 +111,32 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{std::forward(args)...}. \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{unexpected}% \begin{itemdecl} template -constexpr explicit unexpected( - in_place_t, initializer_list il, - Args&&... args) noexcept(is_nothrow_constructible_v&, - Args...>); + constexpr explicit unexpected(in_place_t, initializer_list il, + Args&&... args) noexcept(is_nothrow_constructible_v&, Args...>); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{il, std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{il, std::forward(args)...}. \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \rSec3[expected.un.obs]{Observers} @@ -155,35 +144,27 @@ \indexlibrarymember{error}{unexpected}% \begin{itemdecl} constexpr const E& error() const& noexcept; +constexpr E& error() & noexcept; \end{itemdecl} \begin{itemdescr} \pnum \returns -\tcode{unex}. +\exposid{unex}. \end{itemdescr} -\indexlibrarymember{error}{unexpected}% -\begin{itemdecl} -constexpr E& error() & noexcept; -\end{itemdecl} - \indexlibrarymember{error}{unexpected}% \begin{itemdecl} constexpr const E&& error() const&& noexcept; +constexpr E&& error() && noexcept; \end{itemdecl} \begin{itemdescr} \pnum \returns -\tcode{std::move(unex)}. +\tcode{std::move(\exposid{unex})}. \end{itemdescr} -\indexlibrarymember{error}{unexpected}% -\begin{itemdecl} -constexpr E&& error() && noexcept; -\end{itemdecl} - \rSec3[expected.un.swap]{Swap} \indexlibrarymember{swap}{unexpected}% @@ -198,7 +179,7 @@ \pnum \effects -Equivalent to: \tcode{using std::swap; swap(unex, other.unex);} +Equivalent to: \tcode{using std::swap; swap(\exposid{unex}, other.\exposid{unex});} \end{itemdescr} \indexlibraryglobal{swap}% @@ -221,7 +202,7 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const unexpected& x, const unexpected& y); + friend constexpr bool operator==(const unexpected& x, const unexpected& y); \end{itemdecl} \begin{itemdescr} @@ -266,19 +247,18 @@ } \end{codeblock} -\begin{itemdescr} \pnum \mandates -A program that instantiates the definition of \tcode{unexpected} for a referenced type that is not an object type, an array type, or a specialization of \tcode{unexpected} is ill-formed. +A program that instantiates the definition of \tcode{unexpected} for a referenced type that is not an object type, an array type, or a specialization of \tcode{unexpected} is ill-formed. \pnum \remarks -An object of type \tcode{unexpected} holds a pointer to an object of type \tcode{E}. The referenced object is not owned by the \tcode{unexpected} object. Unlike the primary template, \tcode{E} may be a cv-qualified type. -\end{itemdescr} +An object of type \tcode{unexpected} holds a pointer to an object of type \tcode{E}. The referenced object is not owned by the \tcode{unexpected} object. Unlike the primary template, \tcode{E} may be a cv-qualified type. \indexlibraryctor{unexpected}% \begin{itemdecl} -template constexpr explicit unexpected(G&& e) noexcept; +template + constexpr explicit unexpected(G&& e) noexcept; \end{itemdecl} \begin{itemdescr} @@ -287,32 +267,33 @@ \begin{itemize} \item \tcode{is_same_v, unexpected>} is \tcode{false}, \item \tcode{is_same_v, in_place_t>} is \tcode{false}, -\item \tcode{is_constructible_v} is \tcode{true}, and -\item \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\item \tcode{is_constructible_v} is \tcode{true}, and +\item \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \end{itemize} \pnum \effects -Initializes \tcode{unex} with \tcode{addressof(static_cast(std::forward(e)))}. +Initializes \exposid{unex} with \tcode{addressof(static_cast(std::forward(e)))}. \pnum \remarks -A constructor for which \tcode{reference_constructs_from_temporary_v} is \tcode{true} — one that would bind \tcode{E&} to a temporary — is defined as deleted. +A constructor for which \tcode{reference_constructs_from_temporary_v} is \tcode{true} — one that would bind \tcode{E\&} to a temporary — is defined as deleted. \end{itemdescr} \indexlibraryctor{unexpected}% \begin{itemdecl} -template constexpr explicit unexpected(in_place_t, G&& e) noexcept; +template + constexpr explicit unexpected(in_place_t, G&& e) noexcept; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true} and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\tcode{is_constructible_v} is \tcode{true} and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \pnum \effects -Initializes \tcode{unex} with \tcode{addressof(static_cast(std::forward(e)))}. +Initializes \exposid{unex} with \tcode{addressof(static_cast(std::forward(e)))}. \end{itemdescr} \indexlibrarymember{error}{unexpected}% @@ -323,11 +304,11 @@ \begin{itemdescr} \pnum \returns -\tcode{*unex}. +\tcode{*\exposid{unex}}. \pnum \remarks -The reference returned is not \tcode{const}-qualified even when \tcode{*this} is \tcode{const}; the constness of the \tcode{unexpected} object does not propagate to the referenced object. +The reference returned is not \tcode{const}-qualified even when \tcode{*this} is \tcode{const}; the constness of the \tcode{unexpected} object does not propagate to the referenced object. \end{itemdescr} \indexlibrarymember{swap}{unexpected}% @@ -338,13 +319,13 @@ \begin{itemdescr} \pnum \effects -Exchanges \tcode{unex} and \tcode{other.unex}. +Exchanges \exposid{unex} and \tcode{other.\exposid{unex}}. \end{itemdescr} \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const unexpected& x, const unexpected& y); + friend constexpr bool operator==(const unexpected& x, const unexpected& y); \end{itemdecl} \begin{itemdescr} @@ -399,11 +380,9 @@ } \end{codeblock} -\begin{itemdescr} \pnum \remarks The class template \tcode{bad_expected_access} defines the type of objects thrown as exceptions to report the situation where an attempt is made to access the value of an \tcode{expected} object for which \tcode{has_value()} is \tcode{false}. -\end{itemdescr} \indexlibraryctor{bad_expected_access}% \begin{itemdecl} @@ -457,7 +436,7 @@ \begin{itemdescr} \pnum \returns -\tcode{std::move(unex)}. +\tcode{std::move(\exposid{unex})}. \end{itemdescr} \indexlibrarymember{error}{bad_expected_access}% @@ -468,7 +447,7 @@ \begin{itemdescr} \pnum \returns -\tcode{std::move(unex)}. +\tcode{std::move(\exposid{unex})}. \end{itemdescr} \rSec2[expected.bad.void]{Class template specialization bad_expected_access} @@ -513,310 +492,120 @@ template using rebind = expected; - // ------------------------------------------------------------------------- - // [expected.object.cons] Constructors - // ------------------------------------------------------------------------- - - // Default constructor: value-initializes T - constexpr expected() noexcept(is_nothrow_default_constructible_v) - requires is_default_constructible_v; + constexpr expected() noexcept(is_nothrow_default_constructible_v); - // Copy constructor (trivial path). Unconstrained on purpose: this is the - // sole declaration when T or E is not copy constructible at all (it is - // then implicitly defined as deleted), and the more-constrained - // non-trivial-path overload below is selected over it by constraint - // subsumption whenever it is viable. constexpr expected(const expected&) = default; - // Copy constructor (non-trivial path) - constexpr expected(const expected& rhs) noexcept(is_nothrow_copy_constructible_v && - is_nothrow_copy_constructible_v) - requires(is_copy_constructible_v && is_copy_constructible_v && - !(is_trivially_copy_constructible_v && - is_trivially_copy_constructible_v)); + constexpr expected(const expected& rhs) noexcept( + is_nothrow_copy_constructible_v && is_nothrow_copy_constructible_v); - // Move constructor (trivial path). Unconstrained; see the copy - // constructor above for why. No explicit noexcept: let the compiler - // deduce it, so a non-movable-at-all E deletes rather than mismatches. constexpr expected(expected&&) = default; - // Move constructor (non-trivial path) constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v && - is_nothrow_move_constructible_v) - requires(is_move_constructible_v && is_move_constructible_v && - !(is_trivially_move_constructible_v && - is_trivially_move_constructible_v)); + is_nothrow_move_constructible_v); - // Converting copy constructor from expected — value-E path template - requires(!is_reference_v && is_constructible_v && - is_constructible_v && - (is_same_v> || - !@\exposidnc{converts-from-any-cvref}@>) && - !is_constructible_v, expected&> && - !is_constructible_v, expected&&> && - !is_constructible_v, const expected&> && - !is_constructible_v, const expected&&>) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); - // Converting move constructor from expected — value-E path template - requires(!is_reference_v && is_constructible_v && - is_constructible_v && - (is_same_v> || - !@\exposidnc{converts-from-any-cvref}@>) && - !is_constructible_v, expected&> && - !is_constructible_v, expected&&> && - !is_constructible_v, const expected&> && - !is_constructible_v, const expected&&>) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); - // Converting constructor from expected — reference-E path: only accepts sources - // whose error type G is itself a reference convertible to E. template - requires(is_reference_v && is_reference_v && - is_constructible_v && is_convertible_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); template - requires(is_reference_v && is_reference_v && is_constructible_v && - is_convertible_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); - // Constructor from value U&& template> - requires(!is_same_v, in_place_t> && - !is_same_v, unexpect_t> && - !is_same_v, expected> && is_constructible_v && - !@\exposidnc{is-unexpected-specialization}@>::value && - (!is_same_v> || - !@\exposidnc{is-expected-specialization}@>::value)) constexpr explicit(!is_convertible_v) expected(U&& v); - // Constructor from unexpected const& / && — value-E path template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(const unexpected& e); template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e); - // Constructor from unexpected — reference-E path. Allowed only when G is itself a - // reference, i.e. the source unexpected holds a reference to an external object, so - // binding E& to e.error() cannot dangle regardless of the source's value category. No - // const_cast is needed. template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) + expected(const unexpected& e) noexcept; template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; - // Deleted for reference E with value G: the referent lives inside the unexpected - // object, so binding E& to it would dangle once a temporary source is destroyed. Use - // (unexpect, lvalue), or an unexpected holding an external object, instead. - template - requires(is_reference_v && !is_reference_v) - constexpr expected(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would dangle " - "— use unexpected"); + template constexpr expected(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected(unexpected&&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would dangle " - "— use unexpected"); + constexpr expected(unexpected&&) = delete; - // In-place constructor for value - template - requires is_constructible_v - constexpr explicit expected(in_place_t, Args&&... args); + template constexpr explicit expected(in_place_t, Args&&... args); - // In-place constructor for value with initializer_list template - requires is_constructible_v&, Args...> constexpr explicit expected(in_place_t, initializer_list il, Args&&... args); - // In-place constructor for error - template - requires(is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr explicit expected(unexpect_t, Args&&... args); + template constexpr explicit expected(unexpect_t, Args&&... args); - // Deleted: single argument would bind E& to a temporary — dangling prevention - template - requires(@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " - "temporary that dangles; pass an lvalue reference"); + template constexpr expected(unexpect_t, Args&&...) = delete; - // Deleted catch-all: reference E, argument neither constructible nor a dangling case - // (e.g. binding a non-const E& from a const lvalue). template requires(is_reference_v && !is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = BEMAN_EXPECTED_DELETE_MSG( - "expected: no viable conversion from the given argument(s) to E&"); + constexpr expected(unexpect_t, Args&&...) = delete; - // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); template - requires is_reference_v - constexpr expected(unexpect_t, initializer_list, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG("expected: initializer-list error construction " - "cannot bind a reference; pass an lvalue reference"); - - // ------------------------------------------------------------------------- - // [expected.object.dtor] Destructor - // ------------------------------------------------------------------------- - - constexpr ~expected() - requires(is_trivially_destructible_v && is_trivially_destructible_v) - = default; - - constexpr ~expected() - requires(!(is_trivially_destructible_v && is_trivially_destructible_v)); - - // ------------------------------------------------------------------------- - // [expected.object.assign] Assignment - // ------------------------------------------------------------------------- - - // Copy assignment (trivial path) - constexpr expected& operator=(const expected&) - requires(is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v && - is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v) - = default; - - // Copy assignment (non-trivial path) + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; + + constexpr ~expected() = default; + + constexpr ~expected(); + + constexpr expected& operator=(const expected&) = default; + constexpr expected& operator=(const expected& rhs) noexcept( is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v && - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v) - requires(is_copy_constructible_v && is_copy_assignable_v && - (is_reference_v || - (is_copy_constructible_v && is_copy_assignable_v)) && - (is_nothrow_move_constructible_v || - is_nothrow_move_constructible_v) && - !(is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v && - is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v)); - - // Move assignment (trivial path) - constexpr expected& operator=(expected&&) noexcept - requires(is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v && - is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v) - = default; - - // Move assignment (non-trivial path) + is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); + + constexpr expected& operator=(expected&&) noexcept = default; + constexpr expected& operator=(expected&& rhs) noexcept( is_nothrow_move_constructible_v && is_nothrow_move_assignable_v && - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v) - requires(is_move_constructible_v && is_move_assignable_v && - (is_reference_v || - (is_move_constructible_v && is_move_assignable_v)) && - (is_nothrow_move_constructible_v || - is_nothrow_move_constructible_v) && - !(is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v && - is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v)); - - // Assignment from value U&& - template> - requires(!is_same_v> && - !@\exposidnc{is-unexpected-specialization}@>::value && - is_constructible_v && is_assignable_v && - (is_nothrow_constructible_v || is_nothrow_move_constructible_v || - is_nothrow_move_constructible_v)) - constexpr expected& operator=(U&& v); - - // Assignment from unexpected — value-E path - template - requires(!is_reference_v && is_constructible_v && - is_assignable_v && - (is_nothrow_constructible_v || - is_nothrow_move_constructible_v || is_nothrow_move_constructible_v)) - constexpr expected& operator=(const unexpected& e); + is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); - template - requires(!is_reference_v && is_constructible_v && is_assignable_v && - (is_nothrow_constructible_v || is_nothrow_move_constructible_v || - is_nothrow_move_constructible_v)) - constexpr expected& operator=(unexpected&& e); - - // Rebinding assignment for reference E from reference G — binds unex_ to the external - // referent (never dangles; pointer store is noexcept). Mirrors the reference-E - // constructor. - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(const unexpected& e); + template> constexpr expected& operator=(U&& v); - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(unexpected&& e); + template constexpr expected& operator=(const unexpected& e); - // Deleted for reference E with value G: would rebind E& to unexpected's temporary - // storage. - template - requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(const unexpected&) = - BEMAN_EXPECTED_DELETE_MSG("expected: cannot assign from unexpected; " - "the value would dangle — use unexpected"); + template constexpr expected& operator=(unexpected&& e); + + template constexpr expected& operator=(const unexpected& e); + + template constexpr expected& operator=(unexpected&& e); + + template constexpr expected& operator=(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(unexpected&&) = - BEMAN_EXPECTED_DELETE_MSG("expected: cannot assign from unexpected; " - "the value would dangle — use unexpected"); + constexpr expected& operator=(unexpected&&) = delete; - // Emplace: destroy current value/error, construct value in-place - template - requires is_nothrow_constructible_v - constexpr T& emplace(Args&&... args) noexcept; + template constexpr T& emplace(Args&&... args) noexcept; template - requires is_nothrow_constructible_v&, Args...> constexpr T& emplace(initializer_list il, Args&&... args) noexcept; - // ------------------------------------------------------------------------- - // [expected.object.swap] Swap - // ------------------------------------------------------------------------- - constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && is_nothrow_swappable_v && is_nothrow_move_constructible_v && (is_reference_v || - is_nothrow_swappable_v)) - requires(is_swappable_v && (is_reference_v || is_swappable_v) && - is_move_constructible_v && is_move_constructible_v && - (is_nothrow_move_constructible_v || is_nothrow_move_constructible_v)) - ; - - friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))) - requires(is_swappable_v && (is_reference_v || is_swappable_v) && - is_move_constructible_v && is_move_constructible_v && - (is_nothrow_move_constructible_v || is_nothrow_move_constructible_v)) - ; - - // ------------------------------------------------------------------------- - // [expected.object.obs] Observers - // ------------------------------------------------------------------------- + is_nothrow_swappable_v)); + + friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))); constexpr const T* operator->() const noexcept; constexpr T* operator->() noexcept; @@ -844,81 +633,35 @@ template> constexpr T value_or(U&& def) &&; template - requires(is_copy_constructible_v<@\exposidnc{error-value-type}@> && - is_convertible_v) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; template - requires(is_move_constructible_v<@\exposidnc{error-value-type}@> && - is_convertible_v) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; - // ------------------------------------------------------------------------- - // [expected.object.monadic] Monadic operations - // ------------------------------------------------------------------------- - - template - requires is_constructible_v - constexpr auto and_then(F&& f) &; - template - requires is_constructible_v - constexpr auto and_then(F&& f) &&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&&; - - template - requires is_constructible_v - constexpr auto or_else(F&& f) &; - template - requires is_constructible_v - constexpr auto or_else(F&& f) &&; - template - requires is_constructible_v - constexpr auto or_else(F&& f) const&; - template - requires is_constructible_v - constexpr auto or_else(F&& f) const&&; - - template - requires is_constructible_v - constexpr auto transform(F&& f) &; - template - requires is_constructible_v - constexpr auto transform(F&& f) &&; - template - requires is_constructible_v - constexpr auto transform(F&& f) const&; - template - requires is_constructible_v - constexpr auto transform(F&& f) const&&; - - template - requires is_constructible_v - constexpr auto transform_error(F&& f) &; - template - requires is_constructible_v - constexpr auto transform_error(F&& f) &&; - template - requires is_constructible_v - constexpr auto transform_error(F&& f) const&; - template - requires is_constructible_v - constexpr auto transform_error(F&& f) const&&; - - // ------------------------------------------------------------------------- - // [expected.object.eq] Equality operators (hidden friends) - // ------------------------------------------------------------------------- + template 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&&; template - requires(!is_void_v) friend constexpr bool operator==(const expected& x, const expected& y); template - requires(!@\exposidnc{is-expected-specialization}@::value) friend constexpr bool operator==(const expected& x, const T2& val); template @@ -934,15 +677,13 @@ } \end{codeblock} -\begin{itemdescr} \pnum \mandates A program that instantiates the definition of \tcode{expected} with a \tcode{T} that is not a valid value type for \tcode{expected} (that is, \tcode{remove_cv_t} is \tcode{void}, or a complete non-array object type other than \tcode{in_place_t}, \tcode{unexpect_t}, or a specialization of \tcode{unexpected}) is ill-formed. A program that instantiates the definition of \tcode{expected} with an \tcode{E} that is not a valid template argument for \tcode{unexpected} is ill-formed. \pnum \remarks -Any object of type \tcode{expected} either contains a value of type \tcode{T} or a value of type \tcode{E} nested within it. Member \tcode{has_val} indicates whether the \tcode{expected} object contains an object of type \tcode{T}. When \tcode{has_value()} is \tcode{false}, the error is \tcode{unex.error()}. The error is held as an \tcode{unexpected}, and not as an \tcode{E}, so that \tcode{E} may be an lvalue reference type: an \tcode{E&} cannot be a union member, whereas \tcode{unexpected} holds a pointer to an external object. -\end{itemdescr} +Any object of type \tcode{expected} either contains a value of type \tcode{T} or a value of type \tcode{E} nested within it. Member \tcode{has_val} indicates whether the \tcode{expected} object contains an object of type \tcode{T}. When \tcode{has_value()} is \tcode{false}, the error is \tcode{\exposid{unex}.error()}. The error is held as an \tcode{unexpected}, and not as an \tcode{E}, so that \tcode{E} may be an lvalue reference type: an \tcode{E\&} cannot be a union member, whereas \tcode{unexpected} holds a pointer to an external object. \rSec3[expected.object.cons]{Constructors} @@ -958,7 +699,7 @@ \pnum \effects -Value-initializes \tcode{val}. +Value-initializes \exposid{val}. \pnum \ensures @@ -966,7 +707,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val}. +Any exception thrown by the initialization of \exposid{val}. \end{itemdescr} \indexlibraryctor{expected}% @@ -977,7 +718,7 @@ \begin{itemdescr} \pnum \effects -Direct-non-list-initializes \tcode{val} or \tcode{unex} (matching \tcode{rhs}'s active member) by trivial copy construction. +Direct-non-list-initializes \exposid{val} or \exposid{unex} (matching \tcode{rhs}'s active member) by trivial copy construction. \pnum \ensures @@ -997,11 +738,11 @@ \begin{itemdescr} \pnum \constraints -\tcode{is_copy_constructible_v} is \tcode{true}, \tcode{is_copy_constructible_v} is \tcode{true}, and \tcode{(is_trivially_copy_constructible_v && is_trivially_copy_constructible_v)} is \tcode{false}. +\tcode{is_copy_constructible_v} is \tcode{true}, \tcode{is_copy_constructible_v} is \tcode{true}, and \tcode{(is_trivially_copy_constructible_v \&\& is_trivially_copy_constructible_v)} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, direct-non-list-initializes \tcode{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()} is \tcode{true}, direct-non-list-initializes \exposid{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -1009,7 +750,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val} or \tcode{unex}. +Any exception thrown by the initialization of \exposid{val} or \exposid{unex}. \pnum \remarks @@ -1024,7 +765,7 @@ \begin{itemdescr} \pnum \effects -Direct-non-list-initializes \tcode{val} or \tcode{unex} (matching \tcode{rhs}'s active member) by trivial move construction. +Direct-non-list-initializes \exposid{val} or \exposid{unex} (matching \tcode{rhs}'s active member) by trivial move construction. \pnum \ensures @@ -1037,18 +778,17 @@ \indexlibraryctor{expected}% \begin{itemdecl} -constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v && - is_nothrow_move_constructible_v); +constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v && is_nothrow_move_constructible_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_move_constructible_v} is \tcode{true}, \tcode{is_move_constructible_v} is \tcode{true}, and \tcode{(is_trivially_move_constructible_v && is_trivially_move_constructible_v)} is \tcode{false}. +\tcode{is_move_constructible_v} is \tcode{true}, \tcode{is_move_constructible_v} is \tcode{true}, and \tcode{(is_trivially_move_constructible_v \&\& is_trivially_move_constructible_v)} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, direct-non-list-initializes \tcode{val} with \tcode{std::move(*rhs)}. Otherwise, direct-non-list-initializes \tcode{unex} with \tcode{std::move(rhs.error())}. +If \tcode{rhs.has_value()} is \tcode{true}, direct-non-list-initializes \exposid{val} with \tcode{std::move(*rhs)}. Otherwise, direct-non-list-initializes \exposid{unex} with \tcode{std::move(rhs.error())}. \pnum \ensures @@ -1056,7 +796,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val} or \tcode{unex}. +Any exception thrown by the initialization of \exposid{val} or \exposid{unex}. \pnum \remarks @@ -1066,21 +806,20 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(const expected& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) + expected(const expected& rhs); template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(expected&& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_constructible_v} is \tcode{true}; and if \tcode{T} is not \tcode{bool}, \tcode{converts-from-any-cvref>} is \tcode{false}; and \tcode{is_constructible_v, expected&>} is \tcode{false}; and \tcode{is_constructible_v, expected>} is \tcode{false}; and \tcode{is_constructible_v, const expected&>} is \tcode{false}; and \tcode{is_constructible_v, const expected>} is \tcode{false}. +\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_constructible_v} is \tcode{true}; and if \tcode{T} is not \tcode{bool}, \tcode{converts-from-any-cvref>} is \tcode{false}; and \tcode{is_constructible_v, expected\&>} is \tcode{false}; and \tcode{is_constructible_v, expected>} is \tcode{false}; and \tcode{is_constructible_v, const expected\&>} is \tcode{false}; and \tcode{is_constructible_v, const expected>} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()}, direct-non-list-initializes \tcode{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()}, direct-non-list-initializes \exposid{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -1088,27 +827,25 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val} or \tcode{unex}. +Any exception thrown by the initialization of \exposid{val} or \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(const expected& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(expected&& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_reference_v} is \tcode{true}; and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_reference_v} is \tcode{true}; and \tcode{is_convertible_v} is \tcode{true}. \pnum \effects -If \tcode{rhs.has_value()}, direct-non-list-initializes \tcode{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()}, direct-non-list-initializes \exposid{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -1116,7 +853,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val} or \tcode{unex}. +Any exception thrown by the initialization of \exposid{val} or \exposid{unex}. \pnum \remarks @@ -1126,7 +863,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template> -constexpr explicit(!is_convertible_v) expected(U&& v); + constexpr explicit(!is_convertible_v) expected(U&& v); \end{itemdecl} \begin{itemdescr} @@ -1136,7 +873,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{val} with \tcode{std::forward(v)}. +Direct-non-list-initializes \exposid{val} with \tcode{std::forward(v)}. \pnum \ensures @@ -1144,25 +881,25 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val}. +Any exception thrown by the initialization of \exposid{val}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e); + constexpr explicit(!is_convertible_v) expected(const unexpected& e); template -constexpr explicit(!is_convertible_v) expected(unexpected&& e); + constexpr explicit(!is_convertible_v) expected(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(e.error())}. +Direct-non-list-initializes \exposid{unex} with \tcode{std::forward(e.error())}. \pnum \ensures @@ -1170,15 +907,15 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; template -constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; + constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; \end{itemdecl} \begin{itemdescr} @@ -1188,7 +925,7 @@ \pnum \effects -Initializes \tcode{unex} with \tcode{e.error()}. +Initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -1201,7 +938,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -1211,12 +949,13 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E\&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr explicit expected(in_place_t, Args&&... args); +template + constexpr explicit expected(in_place_t, Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -1226,7 +965,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{val} with \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{val} with \tcode{std::forward(args)...}. \pnum \ensures @@ -1234,23 +973,23 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val}. +Any exception thrown by the initialization of \exposid{val}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit expected(in_place_t, initializer_list il, Args&&... args); + constexpr explicit expected(in_place_t, initializer_list il, Args&&... args); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{val} with \tcode{il, std::forward(args)...}. +Direct-non-list-initializes \exposid{val} with \tcode{il, std::forward(args)...}. \pnum \ensures @@ -1258,12 +997,13 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val}. +Any exception thrown by the initialization of \exposid{val}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr explicit expected(unexpect_t, Args&&... args); +template + constexpr explicit expected(unexpect_t, Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -1273,7 +1013,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{std::forward(args)...}. \pnum \ensures @@ -1281,12 +1021,13 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -1296,23 +1037,23 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. +When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E\&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); + constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{il, std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{il, std::forward(args)...}. \pnum \ensures @@ -1320,7 +1061,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \pnum \remarks @@ -1330,7 +1071,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -1357,7 +1098,7 @@ \pnum \effects -None: \tcode{val} or \tcode{unex} (whichever is active) has a trivial destructor. +None: \exposid{val} or \exposid{unex} (whichever is active) has a trivial destructor. \pnum \remarks @@ -1372,11 +1113,11 @@ \begin{itemdescr} \pnum \constraints -\tcode{(is_trivially_destructible_v && is_trivially_destructible_v)} is \tcode{false}. +\tcode{(is_trivially_destructible_v \&\& is_trivially_destructible_v)} is \tcode{false}. \pnum \effects -If \tcode{has_value()} is \tcode{true}, destroys \tcode{val}, otherwise destroys \tcode{unex}. +If \tcode{has_value()} is \tcode{true}, destroys \exposid{val}, otherwise destroys \exposid{unex}. \end{itemdescr} \rSec3[expected.object.assign]{Assignment} @@ -1413,9 +1154,10 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -constexpr expected& operator=(const expected& rhs) noexcept( - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v && - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); +constexpr expected& operator=(const expected& rhs) noexcept(is_nothrow_copy_constructible_v && + is_nothrow_copy_assignable_v && + is_nothrow_copy_constructible_v && + is_nothrow_copy_assignable_v); \end{itemdecl} \begin{itemdescr} @@ -1424,14 +1166,14 @@ \begin{itemize} \item \tcode{is_copy_constructible_v} is \tcode{true}, \item \tcode{is_copy_assignable_v} is \tcode{true}, -\item \tcode{is_reference_v || (is_copy_constructible_v && is_copy_assignable_v)} is \tcode{true}, +\item \tcode{is_reference_v || (is_copy_constructible_v \&\& is_copy_assignable_v)} is \tcode{true}, \item \tcode{is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}, -\item \tcode{(is_trivially_copy_constructible_v && is_trivially_copy_assignable_v && is_trivially_destructible_v && is_trivially_copy_constructible_v && is_trivially_copy_assignable_v && is_trivially_destructible_v)} is \tcode{false}. +\item \tcode{(is_trivially_copy_constructible_v \&\& is_trivially_copy_assignable_v \&\& is_trivially_destructible_v \&\& is_trivially_copy_constructible_v \&\& is_trivially_copy_assignable_v \&\& is_trivially_destructible_v)} is \tcode{false}. \end{itemize} \pnum \effects -If \tcode{this->has_value() && rhs.has_value()}, equivalent to \tcode{val = *rhs}. Otherwise, if \tcode{this->has_value()}, equivalent to \tcode{reinit-expected(unex, val, rhs.error())}. Otherwise, if \tcode{rhs.has_value()}, equivalent to \tcode{reinit-expected(val, unex, *rhs)}. Otherwise, equivalent to \tcode{unex = rhs.unex}. Then, if no exception was thrown, equivalent to: \tcode{has_val = rhs.has_value(); return *this;} When \tcode{E} is an lvalue reference type, each of the cases above that initializes or assigns \tcode{unex} rebinds it: \tcode{unex} comes to refer to the same object as \tcode{rhs}'s error. No previously or subsequently referenced object is assigned through. +If \tcode{this->has_value() \&\& rhs.has_value()}, equivalent to \tcode{\exposid{val} = *rhs}. Otherwise, if \tcode{this->has_value()}, equivalent to \tcode{reinit-expected(\exposid{unex}, \exposid{val}, rhs.error())}. Otherwise, if \tcode{rhs.has_value()}, equivalent to \tcode{reinit-expected(\exposid{val}, \exposid{unex}, *rhs)}. Otherwise, equivalent to \tcode{\exposid{unex} = rhs.\exposid{unex}}. Then, if no exception was thrown, equivalent to: \tcode{has_val = rhs.has_value(); return *this;} When \tcode{E} is an lvalue reference type, each of the cases above that initializes or assigns \exposid{unex} rebinds it: \exposid{unex} comes to refer to the same object as \tcode{rhs}'s error. No previously or subsequently referenced object is assigned through. \pnum \returns @@ -1474,9 +1216,10 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -constexpr expected& operator=(expected&& rhs) noexcept( - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v && - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); +constexpr expected& operator=(expected&& rhs) noexcept(is_nothrow_move_constructible_v && + is_nothrow_move_assignable_v && + is_nothrow_move_constructible_v && + is_nothrow_move_assignable_v); \end{itemdecl} \begin{itemdescr} @@ -1485,14 +1228,14 @@ \begin{itemize} \item \tcode{is_move_constructible_v} is \tcode{true}, \item \tcode{is_move_assignable_v} is \tcode{true}, -\item \tcode{is_reference_v || (is_move_constructible_v && is_move_assignable_v)} is \tcode{true}, +\item \tcode{is_reference_v || (is_move_constructible_v \&\& is_move_assignable_v)} is \tcode{true}, \item \tcode{is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}, -\item \tcode{(is_trivially_move_constructible_v && is_trivially_move_assignable_v && is_trivially_destructible_v && is_trivially_move_constructible_v && is_trivially_move_assignable_v && is_trivially_destructible_v)} is \tcode{false}. +\item \tcode{(is_trivially_move_constructible_v \&\& is_trivially_move_assignable_v \&\& is_trivially_destructible_v \&\& is_trivially_move_constructible_v \&\& is_trivially_move_assignable_v \&\& is_trivially_destructible_v)} is \tcode{false}. \end{itemize} \pnum \effects -If \tcode{this->has_value() && rhs.has_value()}, equivalent to \tcode{val = std::move(*rhs)}. Otherwise, if \tcode{this->has_value()}, equivalent to \tcode{reinit-expected(unex, val, std::move(rhs.error()))}. Otherwise, if \tcode{rhs.has_value()}, equivalent to \tcode{reinit-expected(val, unex, std::move(*rhs))}. Otherwise, equivalent to \tcode{unex = std::move(rhs.unex)}. Then, if no exception was thrown, equivalent to: \tcode{has_val = rhs.has_value(); return *this;} When \tcode{E} is an lvalue reference type, each of the cases above that initializes or assigns \tcode{unex} rebinds it: \tcode{unex} comes to refer to the same object as \tcode{rhs}'s error. No previously or subsequently referenced object is assigned through. +If \tcode{this->has_value() \&\& rhs.has_value()}, equivalent to \tcode{\exposid{val} = std::move(*rhs)}. Otherwise, if \tcode{this->has_value()}, equivalent to \tcode{reinit-expected(\exposid{unex}, \exposid{val}, std::move(rhs.error()))}. Otherwise, if \tcode{rhs.has_value()}, equivalent to \tcode{reinit-expected(\exposid{val}, \exposid{unex}, std::move(*rhs))}. Otherwise, equivalent to \tcode{\exposid{unex} = std::move(rhs.\exposid{unex})}. Then, if no exception was thrown, equivalent to: \tcode{has_val = rhs.has_value(); return *this;} When \tcode{E} is an lvalue reference type, each of the cases above that initializes or assigns \exposid{unex} rebinds it: \exposid{unex} comes to refer to the same object as \tcode{rhs}'s error. No previously or subsequently referenced object is assigned through. \pnum \returns @@ -1500,22 +1243,23 @@ \pnum \remarks -The exception specification is equivalent to \tcode{is_nothrow_move_assignable_v && is_nothrow_move_constructible_v && is_nothrow_move_assignable_v && is_nothrow_move_constructible_v}. This operator is trivial if \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, \tcode{is_trivially_destructible_v}, \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, and \tcode{is_trivially_destructible_v} are all \tcode{true}. +The exception specification is equivalent to \tcode{is_nothrow_move_assignable_v \&\& is_nothrow_move_constructible_v \&\& is_nothrow_move_assignable_v \&\& is_nothrow_move_constructible_v}. This operator is trivial if \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, \tcode{is_trivially_destructible_v}, \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, and \tcode{is_trivially_destructible_v} are all \tcode{true}. \end{itemdescr} \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template> constexpr expected& operator=(U&& v); +template> + constexpr expected& operator=(U&& v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_same_v>} is \tcode{false}; and \tcode{remove_cvref_t} is not a specialization of \tcode{unexpected}; and \tcode{is_constructible_v} is \tcode{true}; and \tcode{is_assignable_v} is \tcode{true}; and \tcode{is_nothrow_constructible_v || is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}. +\tcode{is_same_v>} is \tcode{false}; and \tcode{remove_cvref_t} is not a specialization of \tcode{unexpected}; and \tcode{is_constructible_v} is \tcode{true}; and \tcode{is_assignable_v} is \tcode{true}; and \tcode{is_nothrow_constructible_v || is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}. \pnum \effects -If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{val = std::forward(v);} Otherwise, equivalent to: \tcode{reinit-expected(val, unex, std::forward(v)); has_val = true;} +If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{\exposid{val} = std::forward(v);} Otherwise, equivalent to: \tcode{reinit-expected(\exposid{val}, \exposid{unex}, std::forward(v)); has_val = true;} \pnum \returns @@ -1524,18 +1268,20 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_assignable_v} is \tcode{true}; and \tcode{is_nothrow_constructible_v || is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_assignable_v} is \tcode{true}; and \tcode{is_nothrow_constructible_v || is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}. \pnum \effects -If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{reinit-expected(unex, val, e.error()); has_val = false;} Otherwise, equivalent to: \tcode{unex = unexpected(e.error());} +If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{reinit-expected(\exposid{unex}, \exposid{val}, e.error()); has_val = false;} Otherwise, equivalent to: \tcode{\exposid{unex} = unexpected(e.error());} \pnum \returns @@ -1544,8 +1290,10 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} @@ -1555,7 +1303,7 @@ \pnum \effects -Rebinds \tcode{unex} to refer to the same object as \tcode{e.error()}, destroying \tcode{val} first if \tcode{has_value()} is \tcode{true}. +Rebinds \exposid{unex} to refer to the same object as \tcode{e.error()}, destroying \exposid{val} first if \tcode{has_value()} is \tcode{true}. \pnum \ensures @@ -1572,7 +1320,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -1582,12 +1331,13 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \tcode{unex} to \tcode{unexpected}'s temporary storage. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \exposid{unex} to \tcode{unexpected}'s temporary storage. \end{itemdescr} \indexlibrarymember{emplace}{expected}% \begin{itemdecl} -template constexpr T& emplace(Args&&... args) noexcept; +template + constexpr T& emplace(Args&&... args) noexcept; \end{itemdecl} \begin{itemdescr} @@ -1597,34 +1347,32 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) { destroy_at(addressof(val)); } else { destroy_at(addressof(unex)); has_val = true; } return *construct_at(addressof(val), std::forward(args)...);} +Equivalent to: \tcode{if (has_value()) \{ destroy_at(addressof(\exposid{val})); \} else \{ destroy_at(addressof(\exposid{unex})); has_val = true; \} return *construct_at(addressof(\exposid{val}), std::forward(args)...);} \end{itemdescr} \indexlibrarymember{emplace}{expected}% \begin{itemdecl} template -constexpr T& emplace(initializer_list il, Args&&... args) noexcept; + constexpr T& emplace(initializer_list il, Args&&... args) noexcept; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_nothrow_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_nothrow_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Equivalent to: \tcode{if (has_value()) { destroy_at(addressof(val)); } else { destroy_at(addressof(unex)); has_val = true; } return *construct_at(addressof(val), il, std::forward(args)...);} +Equivalent to: \tcode{if (has_value()) \{ destroy_at(addressof(\exposid{val})); \} else \{ destroy_at(addressof(\exposid{unex})); has_val = true; \} return *construct_at(addressof(\exposid{val}), il, std::forward(args)...);} \end{itemdescr} \rSec3[expected.object.swap]{Swap} \indexlibrarymember{swap}{expected}% \begin{itemdecl} -constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && - is_nothrow_swappable_v && +constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && is_nothrow_swappable_v && is_nothrow_move_constructible_v && - (is_reference_v || - is_nothrow_swappable_v)); + (is_reference_v || is_nothrow_swappable_v)); \end{itemdecl} \begin{itemdescr} @@ -1640,7 +1388,7 @@ \pnum \effects -If \tcode{this->has_value()} and \tcode{rhs.has_value()}, equivalent to \tcode{using std::swap; swap(val, rhs.val);}. If neither \tcode{*this} nor \tcode{rhs} contains a value, equivalent to \tcode{using std::swap; swap(unex, rhs.unex);}. If \tcode{rhs.has_value()} is \tcode{false} and \tcode{this->has_value()} is \tcode{true}, exchanges the value and error between \tcode{*this} and \tcode{rhs} (moving through a temporary so a failed move leaves both objects unchanged), leaving \tcode{has_value()} \tcode{false} and \tcode{rhs.has_value()} \tcode{true}. If \tcode{rhs.has_value()} is \tcode{true} and \tcode{this->has_value()} is \tcode{false}, equivalent to \tcode{rhs.swap(*this)}. +If \tcode{this->has_value()} and \tcode{rhs.has_value()}, equivalent to \tcode{using std::swap; swap(\exposid{val}, rhs.\exposid{val});}. If neither \tcode{*this} nor \tcode{rhs} contains a value, equivalent to \tcode{using std::swap; swap(\exposid{unex}, rhs.\exposid{unex});}. If \tcode{rhs.has_value()} is \tcode{false} and \tcode{this->has_value()} is \tcode{true}, exchanges the value and error between \tcode{*this} and \tcode{rhs} (moving through a temporary so a failed move leaves both objects unchanged), leaving \tcode{has_value()} \tcode{false} and \tcode{rhs.has_value()} \tcode{true}. If \tcode{rhs.has_value()} is \tcode{true} and \tcode{this->has_value()} is \tcode{false}, equivalent to \tcode{rhs.swap(*this)}. \pnum \throws @@ -1648,7 +1396,7 @@ \pnum \remarks -The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v && is_nothrow_swappable_v && is_nothrow_move_constructible_v && (is_reference_v || is_nothrow_swappable_v)}. +The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v \&\& is_nothrow_swappable_v \&\& is_nothrow_move_constructible_v \&\& (is_reference_v || is_nothrow_swappable_v)}. \end{itemdescr} \indexlibraryglobal{swap}% @@ -1687,7 +1435,7 @@ \pnum \returns -\tcode{addressof(val)}. +\tcode{addressof(\exposid{val})}. \end{itemdescr} \indexlibrarymember{operator*}{expected}% @@ -1703,7 +1451,7 @@ \pnum \returns -\tcode{val}. +\exposid{val}. \end{itemdescr} \indexlibrarymember{operator*}{expected}% @@ -1719,7 +1467,7 @@ \pnum \returns -\tcode{std::move(val)}. +\tcode{std::move(\exposid{val})}. \end{itemdescr} \indexlibrarymember{operator bool}{expected}% @@ -1748,7 +1496,7 @@ \pnum \returns -\tcode{val}, if \tcode{has_value()} is \tcode{true}. +\exposid{val}, if \tcode{has_value()} is \tcode{true}. \pnum \throws @@ -1768,7 +1516,7 @@ \pnum \returns -\tcode{std::move(val)}, if \tcode{has_value()} is \tcode{true}. +\tcode{std::move(\exposid{val})}, if \tcode{has_value()} is \tcode{true}. \pnum \throws @@ -1788,7 +1536,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -1804,12 +1552,13 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{value_or}{expected}% \begin{itemdecl} -template> constexpr T value_or(U&& def) const&; +template> + constexpr T value_or(U&& def) const&; \end{itemdecl} \begin{itemdescr} @@ -1824,7 +1573,8 @@ \indexlibrarymember{value_or}{expected}% \begin{itemdecl} -template> constexpr T value_or(U&& def) &&; +template> + constexpr T value_or(U&& def) &&; \end{itemdecl} \begin{itemdescr} @@ -1840,17 +1590,17 @@ \indexlibrarymember{error_or}{expected}% \begin{itemdecl} template -constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_copy_constructible_v::error_value_type>} is \tcode{true} and \tcode{is_convertible_v::error_value_type>} is \tcode{true}. +\tcode{is_copy_constructible_v::\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v::\exposid{error-value-type}>} is \tcode{true}. \pnum \mandates -\tcode{is_copy_constructible_v} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_copy_constructible_v<\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. \pnum \returns @@ -1859,17 +1609,18 @@ \indexlibrarymember{error_or}{expected}% \begin{itemdecl} -template constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; +template + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_move_constructible_v::error_value_type>} is \tcode{true} and \tcode{is_convertible_v::error_value_type>} is \tcode{true}. +\tcode{is_move_constructible_v::\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v::\exposid{error-value-type}>} is \tcode{true}. \pnum \mandates -\tcode{is_move_constructible_v} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_move_constructible_v<\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. \pnum \returns @@ -1880,8 +1631,10 @@ \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &; -template constexpr auto and_then(F&& f) const&; +template + constexpr auto and_then(F&& f) &; +template + constexpr auto and_then(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -1891,17 +1644,19 @@ \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), val); else return U(unexpect, error());} where \tcode{U} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), \exposid{val}); else return U(unexpect, error());} where \tcode{U} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &&; -template constexpr auto and_then(F&& f) const&&; +template + constexpr auto and_then(F&& f) &&; +template + constexpr auto and_then(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -1911,23 +1666,25 @@ \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), std::move(val)); else return U(unexpect, std::move(error()));} where \tcode{U} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), std::move(\exposid{val})); else return U(unexpect, std::move(error()));} where \tcode{U} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &; -template constexpr auto or_else(F&& f) const&; +template + constexpr auto or_else(F&& f) &; +template + constexpr auto or_else(F&& f) const&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1935,19 +1692,21 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(in_place, val); else return invoke(std::forward(f), error());} where \tcode{G} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return G(in_place, \exposid{val}); else return invoke(std::forward(f), error());} where \tcode{G} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &&; -template constexpr auto or_else(F&& f) const&&; +template + constexpr auto or_else(F&& f) &&; +template + constexpr auto or_else(F&& f) const&&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1955,13 +1714,15 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(in_place, std::move(val)); else return invoke(std::forward(f), std::move(error()));} where \tcode{G} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return G(in_place, std::move(\exposid{val})); else return invoke(std::forward(f), std::move(error()));} where \tcode{G} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &; -template constexpr auto transform(F&& f) const&; +template + constexpr auto transform(F&& f) &; +template + constexpr auto transform(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -1971,13 +1732,15 @@ \pnum \effects -Equivalent to: \tcode{if (!has_value()) return U(unexpect, error()); else return expected(in_place, invoke(std::forward(f), val));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. +Equivalent to: \tcode{if (!has_value()) return U(unexpect, error()); else return expected(in_place, invoke(std::forward(f), \exposid{val}));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &&; -template constexpr auto transform(F&& f) const&&; +template + constexpr auto transform(F&& f) &&; +template + constexpr auto transform(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -1987,19 +1750,21 @@ \pnum \effects -Equivalent to: \tcode{if (!has_value()) return U(unexpect, std::move(error())); else return expected(in_place, invoke(std::forward(f), std::move(val)));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. +Equivalent to: \tcode{if (!has_value()) return U(unexpect, std::move(error())); else return expected(in_place, invoke(std::forward(f), std::move(\exposid{val})));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &; -template constexpr auto transform_error(F&& f) const&; +template + constexpr auto transform_error(F&& f) &; +template + constexpr auto transform_error(F&& f) const&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -2012,19 +1777,21 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(in_place, val); else return expected(unexpect, invoke(std::forward(f), error()));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. +Equivalent to: \tcode{if (has_value()) return G(in_place, \exposid{val}); else return expected(unexpect, invoke(std::forward(f), error()));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &&; -template constexpr auto transform_error(F&& f) const&&; +template + constexpr auto transform_error(F&& f) &&; +template + constexpr auto transform_error(F&& f) const&&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -2037,7 +1804,7 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(in_place, std::move(val)); else return expected(unexpect, invoke(std::forward(f), std::move(error())));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. +Equivalent to: \tcode{if (has_value()) return G(in_place, std::move(\exposid{val})); else return expected(unexpect, invoke(std::forward(f), std::move(error())));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. \end{itemdescr} \rSec3[expected.object.eq]{Equality operators} @@ -2045,7 +1812,7 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const expected& y); + friend constexpr bool operator==(const expected& x, const expected& y); \end{itemdecl} \begin{itemdescr} @@ -2064,7 +1831,8 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} -template friend constexpr bool operator==(const expected& x, const T2& val); +template + friend constexpr bool operator==(const expected& x, const T2& val); \end{itemdecl} \begin{itemdescr} @@ -2078,13 +1846,13 @@ \pnum \returns -\tcode{x.has_value() && static_cast(*x == val)}. +\tcode{x.has_value() \&\& static_cast(*x == val)}. \end{itemdescr} \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const unexpected& e); + friend constexpr bool operator==(const expected& x, const unexpected& e); \end{itemdecl} \begin{itemdescr} @@ -2094,7 +1862,7 @@ \pnum \returns -\tcode{!x.has_value() && static_cast(x.error() == e.error())}. +\tcode{!x.has_value() \&\& static_cast(x.error() == e.error())}. \end{itemdescr} \rSec2[expected.void]{Partial specialization of expected for void types} @@ -2115,221 +1883,92 @@ template using rebind = expected; - // ------------------------------------------------------------------------- - // [expected.void.cons] Constructors - // ------------------------------------------------------------------------- - constexpr expected() noexcept; - // Unconstrained trivial-path candidate: see the primary template's copy - // constructor for why (the sole declaration when E is not copy - // constructible at all; subsumed by the non-trivial path otherwise). - - constexpr expected(const expected& rhs) noexcept(is_nothrow_copy_constructible_v) - requires(is_copy_constructible_v && !is_trivially_copy_constructible_v); - - // Unconstrained; no explicit noexcept — see the primary template's move - // constructor for why. + constexpr expected(const expected& rhs) noexcept( + is_nothrow_copy_constructible_v); - constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v) - requires(is_move_constructible_v && !is_trivially_move_constructible_v); + constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v); - // Converting constructor from expected where is_void_v. Excludes U,G exactly - // matching this class's own void,E (the real copy/move constructors already handle - // that case) — instantiating this template for the self-referential case would - // otherwise probe unexpected's constructibility from this very class, which some - // standard library implementations of reference_constructs_from_temporary_v resolve - // as a circular constraint. template - requires(is_void_v && !is_reference_v && !is_same_v && - is_constructible_v && - !is_constructible_v, expected&> && - !is_constructible_v, expected&&> && - !is_constructible_v, const expected&> && - !is_constructible_v, const expected&&>) constexpr explicit(!is_convertible_v) expected(const expected& rhs); template - requires(is_void_v && !is_reference_v && !is_same_v && - is_constructible_v && - !is_constructible_v, expected&> && - !is_constructible_v, expected&&> && - !is_constructible_v, const expected&> && - !is_constructible_v, const expected&&>) constexpr explicit(!is_convertible_v) expected(expected&& rhs); - // Constructor from unexpected const& / && — value-E path template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(const unexpected& e); template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e); - // Constructor from unexpected — reference-E path. Allowed only when G is itself a - // reference, so e.error() refers to an external object and binding E& cannot dangle. - // No const_cast needed. template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) + expected(const unexpected& e) noexcept; template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; - // Deleted for reference E with value G: the referent lives inside the temporary - // unexpected, so binding E& to it would dangle once the source is destroyed. Use - // (unexpect, lvalue) instead. - template - requires(is_reference_v && !is_reference_v) - constexpr expected(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would " - "dangle — use unexpected"); + template constexpr expected(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected(unexpected&&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would " - "dangle — use unexpected"); + constexpr expected(unexpected&&) = delete; - // In-place constructor for value (no args, just marks has-value) constexpr explicit expected(in_place_t) noexcept; - // In-place constructor for error - template - requires(is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr explicit expected(unexpect_t, Args&&... args); + template constexpr explicit expected(unexpect_t, Args&&... args); - // Deleted: single argument would bind E& to a temporary — dangling prevention - template - requires(@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " - "temporary that dangles; pass an lvalue reference"); + template constexpr expected(unexpect_t, Args&&...) = delete; - // Deleted catch-all: reference E, argument neither constructible nor a dangling case - // (e.g. binding a non-const E& from a const lvalue). template requires(is_reference_v && !is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = BEMAN_EXPECTED_DELETE_MSG( - "expected: no viable conversion from the given argument(s) to E&"); + constexpr expected(unexpect_t, Args&&...) = delete; - // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); template - requires is_reference_v - constexpr expected(unexpect_t, initializer_list, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG( - "expected: initializer-list error construction cannot bind a " - "reference; pass an lvalue reference"); - - // Converting constructor from expected — reference-E path only. G is itself - // a reference to an external object, so binding E& to it cannot dangle regardless of - // the source's value category, provided the reference conversion itself does not - // materialize a temporary (e.g. a base-from-derived or qualification conversion is - // fine; a user-defined conversion that returns by value is not). Mirrors the - // unexpected reference-E path above. + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; + template - requires(is_reference_v && is_convertible_v && - !reference_constructs_from_temporary_v) - constexpr explicit(!is_convertible_v) expected(const expected& rhs); + constexpr explicit(!is_convertible_v) + expected(const expected& rhs); template - requires(is_reference_v && is_convertible_v && - !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(expected&& rhs); - // ------------------------------------------------------------------------- - // [expected.void.dtor] Destructor - // ------------------------------------------------------------------------- - constexpr ~expected(); - // ------------------------------------------------------------------------- - // [expected.void.assign] Assignment - // ------------------------------------------------------------------------- - - // Copy assignment (trivial path) - - // Copy assignment (non-trivial path) constexpr expected& operator=(const expected& rhs) noexcept( - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v) - requires((is_reference_v || - (is_copy_constructible_v && is_copy_assignable_v)) && - !(is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v)); - - // Move assignment (trivial path) + is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); - // Move assignment (non-trivial path) constexpr expected& operator=(expected&& rhs) noexcept( - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v) - requires((is_reference_v || - (is_move_constructible_v && is_move_assignable_v)) && - !(is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v)); + is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); - // Assignment from unexpected — value-E path. - template - requires(!is_reference_v && is_constructible_v && - is_assignable_v) - constexpr expected& operator=(const unexpected& e); + template constexpr expected& operator=(const unexpected& e); - template - requires(!is_reference_v && is_constructible_v && is_assignable_v) - constexpr expected& operator=(unexpected&& e); + template constexpr expected& operator=(unexpected&& e); - // Rebinding assignment for reference E from reference G — binds unex_ to the external - // referent. - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(const unexpected& e); + template constexpr expected& operator=(const unexpected& e); - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(unexpected&& e); + template constexpr expected& operator=(unexpected&& e); - // Deleted for reference E with value G: would bind E& to storage inside the temporary - // unexpected. - template - requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot assign from unexpected; the value would dangle " - "— use unexpected"); + template constexpr expected& operator=(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(unexpected&&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot assign from unexpected; the value would dangle " - "— use unexpected"); + constexpr expected& operator=(unexpected&&) = delete; constexpr void emplace() noexcept; - // ------------------------------------------------------------------------- - // [expected.void.swap] Swap - // ------------------------------------------------------------------------- - constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && (is_reference_v || - is_nothrow_swappable_v)) - requires((is_reference_v || is_swappable_v) && is_move_constructible_v); + is_nothrow_swappable_v)); - friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))) - requires((is_reference_v || is_swappable_v) && is_move_constructible_v); - - // ------------------------------------------------------------------------- - // [expected.void.obs] Observers - // ------------------------------------------------------------------------- + friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))); constexpr explicit operator bool() const noexcept; constexpr bool has_value() const noexcept; @@ -2339,78 +1978,40 @@ constexpr void value() const&; constexpr void value() &&; - // error() — shallow const for reference E: always returns E& regardless of const on - // expected constexpr const E& error() const& noexcept; constexpr E& error() & noexcept; constexpr const E&& error() const&& noexcept; constexpr E&& error() && noexcept; template - requires(is_copy_constructible_v>> && - is_convertible_v>>) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; template - requires(is_move_constructible_v>> && - is_convertible_v>>) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; - // Deleted: value_or is not available for void expected. Gated to reference E only so - // that, for value E, no value_or overload is declared at all (there is nothing to - // delete against). - template - requires is_reference_v - constexpr void value_or(U&&) const = BEMAN_EXPECTED_DELETE_MSG( - "expected: value_or is not defined for void value_type; there is no " - "value to fall back from — use has_value()/error()"); - - // ------------------------------------------------------------------------- - // [expected.void.monadic] Monadic operations - // ------------------------------------------------------------------------- - - template - requires is_constructible_v - constexpr auto and_then(F&& f) &; - template - requires is_constructible_v - constexpr auto and_then(F&& f) &&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&&; + template constexpr void value_or(U&&) const = delete; + + template 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 - requires is_constructible_v - constexpr auto transform(F&& f) &; - template - requires is_constructible_v - constexpr auto transform(F&& f) &&; - template - requires is_constructible_v - constexpr auto transform(F&& f) const&; - template - requires is_constructible_v - constexpr auto transform(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 operators (hidden friends) - // ------------------------------------------------------------------------- - template - requires is_void_v friend constexpr bool operator==(const expected& x, const expected& y); template @@ -2425,15 +2026,13 @@ } \end{codeblock} -\begin{itemdescr} \pnum \mandates A program that instantiates the definition of \tcode{expected} with an \tcode{E} that is not a valid template argument for \tcode{unexpected} is ill-formed. \pnum \remarks -Any object of type \tcode{expected} either represents a value of type \tcode{T}, or contains a value of type \tcode{E} nested within it. Member \tcode{has_val} indicates whether the \tcode{expected} object represents a value of type \tcode{T}. When \tcode{has_value()} is \tcode{false}, the error is \tcode{unex.error()}. -\end{itemdescr} +Any object of type \tcode{expected} either represents a value of type \tcode{T}, or contains a value of type \tcode{E} nested within it. Member \tcode{has_val} indicates whether the \tcode{expected} object represents a value of type \tcode{T}. When \tcode{has_value()} is \tcode{false}, the error is \tcode{\exposid{unex}.error()}. \rSec3[expected.void.cons]{Constructors} @@ -2460,7 +2059,7 @@ \pnum \effects -If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -2468,7 +2067,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \pnum \remarks @@ -2487,7 +2086,7 @@ \pnum \effects -If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \tcode{unex} with \tcode{std::move(rhs.error())}. +If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \exposid{unex} with \tcode{std::move(rhs.error())}. \pnum \ensures @@ -2495,7 +2094,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \pnum \remarks @@ -2505,19 +2104,19 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const expected& rhs); + constexpr explicit(!is_convertible_v) expected(const expected& rhs); template -constexpr explicit(!is_convertible_v) expected(expected&& rhs); + constexpr explicit(!is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_void_v} is \tcode{true}; and \tcode{is_constructible_v} is \tcode{true}; and \tcode{is_constructible_v, expected&>} is \tcode{false}; and \tcode{is_constructible_v, expected>} is \tcode{false}; and \tcode{is_constructible_v, const expected&>} is \tcode{false}; and \tcode{is_constructible_v, const expected>} is \tcode{false}. +\tcode{is_void_v} is \tcode{true}; and \tcode{is_constructible_v} is \tcode{true}; and \tcode{is_constructible_v, expected\&>} is \tcode{false}; and \tcode{is_constructible_v, expected>} is \tcode{false}; and \tcode{is_constructible_v, const expected\&>} is \tcode{false}; and \tcode{is_constructible_v, const expected>} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -2525,25 +2124,25 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e); + constexpr explicit(!is_convertible_v) expected(const unexpected& e); template -constexpr explicit(!is_convertible_v) expected(unexpected&& e); + constexpr explicit(!is_convertible_v) expected(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{e.error()}. +Direct-non-list-initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -2551,15 +2150,15 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; template -constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; + constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; \end{itemdecl} \begin{itemdescr} @@ -2569,7 +2168,7 @@ \pnum \effects -Initializes \tcode{unex} with \tcode{e.error()}. +Initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -2582,7 +2181,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -2592,7 +2192,7 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E\&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. \end{itemdescr} \indexlibraryctor{expected}% @@ -2608,7 +2208,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr explicit expected(unexpect_t, Args&&... args); +template + constexpr explicit expected(unexpect_t, Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -2618,7 +2219,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{std::forward(args)...}. \pnum \ensures @@ -2626,12 +2227,13 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -2641,23 +2243,23 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. +When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E\&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); + constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{il, std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{il, std::forward(args)...}. \pnum \ensures @@ -2665,7 +2267,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \pnum \remarks @@ -2675,7 +2277,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -2691,19 +2293,19 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const expected& rhs); + constexpr explicit(!is_convertible_v) expected(const expected& rhs); template -constexpr explicit(!is_convertible_v) expected(expected&& rhs); + constexpr explicit(!is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_convertible_v} is \tcode{true}; and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\tcode{is_convertible_v} is \tcode{true}; and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -2724,7 +2326,7 @@ \begin{itemdescr} \pnum \effects -If \tcode{has_value()} is \tcode{false}, destroys \tcode{unex}. +If \tcode{has_value()} is \tcode{false}, destroys \exposid{unex}. \pnum \remarks @@ -2735,18 +2337,18 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -constexpr expected& operator=(const expected& rhs) noexcept( - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); +constexpr expected& operator=(const expected& rhs) noexcept(is_nothrow_copy_constructible_v && + is_nothrow_copy_assignable_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v || (is_copy_constructible_v && is_copy_assignable_v)} is \tcode{true} and \tcode{(is_trivially_copy_constructible_v && is_trivially_copy_assignable_v && is_trivially_destructible_v)} is \tcode{false}. +\tcode{is_reference_v || (is_copy_constructible_v \&\& is_copy_assignable_v)} is \tcode{true} and \tcode{(is_trivially_copy_constructible_v \&\& is_trivially_copy_assignable_v \&\& is_trivially_destructible_v)} is \tcode{false}. \pnum \effects -If \tcode{this->has_value() && rhs.has_value()}, no effects. Otherwise, if \tcode{this->has_value()}, equivalent to: \tcode{construct_at(addressof(unex), rhs.unex); has_val = false;} Otherwise, if \tcode{rhs.has_value()}, destroys \tcode{unex} and sets \tcode{has_val} to \tcode{true}. Otherwise, equivalent to \tcode{unex = rhs.unex}. +If \tcode{this->has_value() \&\& rhs.has_value()}, no effects. Otherwise, if \tcode{this->has_value()}, equivalent to: \tcode{construct_at(addressof(\exposid{unex}), rhs.\exposid{unex}); has_val = false;} Otherwise, if \tcode{rhs.has_value()}, destroys \exposid{unex} and sets \tcode{has_val} to \tcode{true}. Otherwise, equivalent to \tcode{\exposid{unex} = rhs.\exposid{unex}}. \pnum \returns @@ -2759,18 +2361,18 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -constexpr expected& operator=(expected&& rhs) noexcept( - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); +constexpr expected& operator=(expected&& rhs) noexcept(is_nothrow_move_constructible_v && + is_nothrow_move_assignable_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v || (is_move_constructible_v && is_move_assignable_v)} is \tcode{true} and \tcode{(is_trivially_move_constructible_v && is_trivially_move_assignable_v && is_trivially_destructible_v)} is \tcode{false}. +\tcode{is_reference_v || (is_move_constructible_v \&\& is_move_assignable_v)} is \tcode{true} and \tcode{(is_trivially_move_constructible_v \&\& is_trivially_move_assignable_v \&\& is_trivially_destructible_v)} is \tcode{false}. \pnum \effects -If \tcode{this->has_value() && rhs.has_value()}, no effects. Otherwise, if \tcode{this->has_value()}, equivalent to: \tcode{construct_at(addressof(unex), std::move(rhs.unex)); has_val = false;} Otherwise, if \tcode{rhs.has_value()}, destroys \tcode{unex} and sets \tcode{has_val} to \tcode{true}. Otherwise, equivalent to \tcode{unex = std::move(rhs.unex)}. +If \tcode{this->has_value() \&\& rhs.has_value()}, no effects. Otherwise, if \tcode{this->has_value()}, equivalent to: \tcode{construct_at(addressof(\exposid{unex}), std::move(rhs.\exposid{unex})); has_val = false;} Otherwise, if \tcode{rhs.has_value()}, destroys \exposid{unex} and sets \tcode{has_val} to \tcode{true}. Otherwise, equivalent to \tcode{\exposid{unex} = std::move(rhs.\exposid{unex})}. \pnum \returns @@ -2778,23 +2380,25 @@ \pnum \remarks -The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v && is_nothrow_move_assignable_v}. This operator is trivial if \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, and \tcode{is_trivially_destructible_v} are all \tcode{true}. +The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v \&\& is_nothrow_move_assignable_v}. This operator is trivial if \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, and \tcode{is_trivially_destructible_v} are all \tcode{true}. \end{itemdescr} \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true} and \tcode{is_assignable_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true} and \tcode{is_assignable_v} is \tcode{true}. \pnum \effects -If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{construct_at(addressof(unex), e.error()); has_val = false;} Otherwise, equivalent to: \tcode{unex = unexpected(e.error());} +If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{construct_at(addressof(\exposid{unex}), e.error()); has_val = false;} Otherwise, equivalent to: \tcode{\exposid{unex} = unexpected(e.error());} \pnum \returns @@ -2803,8 +2407,10 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} @@ -2814,7 +2420,7 @@ \pnum \effects -Rebinds \tcode{unex} to refer to the same object as \tcode{e.error()}. +Rebinds \exposid{unex} to refer to the same object as \tcode{e.error()}. \pnum \ensures @@ -2831,7 +2437,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -2841,7 +2448,7 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \tcode{unex} to \tcode{unexpected}'s temporary storage. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \exposid{unex} to \tcode{unexpected}'s temporary storage. \end{itemdescr} \indexlibrarymember{emplace}{expected}% @@ -2852,7 +2459,7 @@ \begin{itemdescr} \pnum \effects -If \tcode{has_value()} is \tcode{false}, destroys \tcode{unex} and sets \tcode{has_val} to \tcode{true}. +If \tcode{has_value()} is \tcode{false}, destroys \exposid{unex} and sets \tcode{has_val} to \tcode{true}. \end{itemdescr} \rSec3[expected.void.swap]{Swap} @@ -2860,8 +2467,7 @@ \indexlibrarymember{swap}{expected}% \begin{itemdecl} constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && - (is_reference_v || - is_nothrow_swappable_v)); + (is_reference_v || is_nothrow_swappable_v)); \end{itemdecl} \begin{itemdescr} @@ -2871,7 +2477,7 @@ \pnum \effects -If \tcode{this->has_value()} and \tcode{rhs.has_value()}, no effects. If neither \tcode{*this} nor \tcode{rhs} contains a value, equivalent to \tcode{using std::swap; swap(unex, rhs.unex);}. If \tcode{rhs.has_value()} is \tcode{false} and \tcode{this->has_value()} is \tcode{true}, initializes \tcode{rhs.unex} from \tcode{std::move(unex)}, destroys \tcode{unex}, and leaves \tcode{has_value()} \tcode{false} and \tcode{rhs.has_value()} \tcode{true}. If \tcode{rhs.has_value()} is \tcode{true} and \tcode{this->has_value()} is \tcode{false}, equivalent to \tcode{rhs.swap(*this)}. +If \tcode{this->has_value()} and \tcode{rhs.has_value()}, no effects. If neither \tcode{*this} nor \tcode{rhs} contains a value, equivalent to \tcode{using std::swap; swap(\exposid{unex}, rhs.\exposid{unex});}. If \tcode{rhs.has_value()} is \tcode{false} and \tcode{this->has_value()} is \tcode{true}, initializes \tcode{rhs.\exposid{unex}} from \tcode{std::move(\exposid{unex})}, destroys \exposid{unex}, and leaves \tcode{has_value()} \tcode{false} and \tcode{rhs.has_value()} \tcode{true}. If \tcode{rhs.has_value()} is \tcode{true} and \tcode{this->has_value()} is \tcode{false}, equivalent to \tcode{rhs.swap(*this)}. \pnum \throws @@ -2879,7 +2485,7 @@ \pnum \remarks -The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v && (is_reference_v || is_nothrow_swappable_v)}. +The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v \&\& (is_reference_v || is_nothrow_swappable_v)}. \end{itemdescr} \indexlibraryglobal{swap}% @@ -2966,7 +2572,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -2982,13 +2588,13 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{error_or}{expected}% \begin{itemdecl} template -constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; \end{itemdecl} \begin{itemdescr} @@ -2998,7 +2604,7 @@ \pnum \mandates -\tcode{is_copy_constructible_v} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_copy_constructible_v<\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. \pnum \returns @@ -3007,7 +2613,8 @@ \indexlibrarymember{error_or}{expected}% \begin{itemdecl} -template constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; +template + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; \end{itemdecl} \begin{itemdescr} @@ -3017,7 +2624,7 @@ \pnum \mandates -\tcode{is_move_constructible_v} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_move_constructible_v<\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. \pnum \returns @@ -3026,7 +2633,8 @@ \indexlibrarymember{value_or}{expected}% \begin{itemdecl} -template constexpr void value_or(U&&) const; +template + constexpr void value_or(U&&) const = delete; \end{itemdecl} \begin{itemdescr} @@ -3043,8 +2651,10 @@ \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &; -template constexpr auto and_then(F&& f) const&; +template + constexpr auto and_then(F&& f) &; +template + constexpr auto and_then(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -3063,8 +2673,10 @@ \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &&; -template constexpr auto and_then(F&& f) const&&; +template + constexpr auto and_then(F&& f) &&; +template + constexpr auto and_then(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -3083,8 +2695,10 @@ \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &; -template constexpr auto or_else(F&& f) const&; +template + constexpr auto or_else(F&& f) &; +template + constexpr auto or_else(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -3099,8 +2713,10 @@ \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &&; -template constexpr auto or_else(F&& f) const&&; +template + constexpr auto or_else(F&& f) &&; +template + constexpr auto or_else(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -3115,8 +2731,10 @@ \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &; -template constexpr auto transform(F&& f) const&; +template + constexpr auto transform(F&& f) &; +template + constexpr auto transform(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -3135,8 +2753,10 @@ \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &&; -template constexpr auto transform(F&& f) const&&; +template + constexpr auto transform(F&& f) &&; +template + constexpr auto transform(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -3155,8 +2775,10 @@ \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &; -template constexpr auto transform_error(F&& f) const&; +template + constexpr auto transform_error(F&& f) &; +template + constexpr auto transform_error(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -3166,13 +2788,15 @@ \pnum \returns -If \tcode{has_value()} is \tcode{true}, \tcode{expected()}; otherwise, an \tcode{expected} object whose \tcode{has_val} member is \tcode{false} and \tcode{unex} member is direct-non-list-initialized with \tcode{invoke(std::forward(f), error())}. +If \tcode{has_value()} is \tcode{true}, \tcode{expected()}; otherwise, an \tcode{expected} object whose \tcode{has_val} member is \tcode{false} and \exposid{unex} member is direct-non-list-initialized with \tcode{invoke(std::forward(f), error())}. \end{itemdescr} \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &&; -template constexpr auto transform_error(F&& f) const&&; +template + constexpr auto transform_error(F&& f) &&; +template + constexpr auto transform_error(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -3182,7 +2806,7 @@ \pnum \returns -If \tcode{has_value()} is \tcode{true}, \tcode{expected()}; otherwise, an \tcode{expected} object whose \tcode{has_val} member is \tcode{false} and \tcode{unex} member is direct-non-list-initialized with \tcode{invoke(std::forward(f), std::move(error()))}. +If \tcode{has_value()} is \tcode{true}, \tcode{expected()}; otherwise, an \tcode{expected} object whose \tcode{has_val} member is \tcode{false} and \exposid{unex} member is direct-non-list-initialized with \tcode{invoke(std::forward(f), std::move(error()))}. \end{itemdescr} \rSec3[expected.void.eq]{Equality operators} @@ -3190,7 +2814,7 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const expected& y); + friend constexpr bool operator==(const expected& x, const expected& y); \end{itemdecl} \begin{itemdescr} @@ -3210,7 +2834,7 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const unexpected& e); + friend constexpr bool operator==(const expected& x, const unexpected& e); \end{itemdecl} \begin{itemdescr} @@ -3220,7 +2844,7 @@ \pnum \returns -\tcode{!x.has_value() && static_cast(x.error() == e.error())}. +\tcode{!x.has_value() \&\& static_cast(x.error() == e.error())}. \end{itemdescr} \rSec2[expected.ref]{Partial specialization of expected for reference types} @@ -3241,253 +2865,113 @@ template using rebind = expected; - // ------------------------------------------------------------------------- - // Constructors - // ------------------------------------------------------------------------- + expected() = delete; - expected() = BEMAN_EXPECTED_DELETE_MSG( - "expected: no default constructor; T& cannot be null"); - - // Copy constructor (trivial path). Unconstrained; see the primary - // template's copy constructor for why. constexpr expected(const expected&) = default; - // Copy constructor (non-trivial path) - constexpr expected(const expected& rhs) noexcept(is_nothrow_copy_constructible_v) - requires(is_copy_constructible_v && !is_trivially_copy_constructible_v); + constexpr expected(const expected& rhs) noexcept( + is_nothrow_copy_constructible_v); - // Move constructor (trivial path). Unconstrained; no explicit noexcept. constexpr expected(expected&&) = default; - // Move constructor (non-trivial path) - constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v) - requires(is_move_constructible_v && !is_trivially_move_constructible_v); + constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v); - // Deleted: no in-place value constructor — T& cannot be constructed in-place - template - constexpr expected(in_place_t, Args&&...) = BEMAN_EXPECTED_DELETE_MSG( - "expected: no in-place value constructor; T& cannot be constructed " - "in-place — pass a U convertible to T&"); + template constexpr expected(in_place_t, Args&&...) = delete; - // Value constructor — takes U that can bind to T& template - requires(!is_same_v, in_place_t> && - !is_same_v, expected> && - !@\exposidnc{is-unexpected-specialization}@>::value && - is_constructible_v && !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(U&& u) noexcept(is_nothrow_constructible_v); - // Deleted: binding a temporary to T& creates a dangling reference - template - requires(reference_constructs_from_temporary_v) - constexpr expected(U&&) = - BEMAN_EXPECTED_DELETE_MSG("expected: argument would bind a temporary that " - "dangles; pass an lvalue reference"); + template constexpr expected(U&&) = delete; - // Converting constructor from expected (copy) — value-E path template - requires(!is_reference_v && is_constructible_v && - is_constructible_v && - !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); - // Converting constructor from expected (move) — value-E path template - requires(!is_reference_v && is_constructible_v && - is_constructible_v && !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); - // Converting constructor from expected (copy/move) — reference-E path: only - // accepts sources whose error type G is itself a reference convertible to E. template - requires(is_reference_v && is_reference_v && is_constructible_v && - is_convertible_v && !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); template - requires(is_reference_v && is_reference_v && is_constructible_v && - is_convertible_v && !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); - // Constructor from unexpected const& / && — value-E path template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(const unexpected& e); template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e); - // Constructor from unexpected — reference-E path. Allowed only when G is itself a - // reference, i.e. the source unexpected holds a reference to an external object, so - // binding E& to e.error() cannot dangle regardless of the source's value category. No - // const_cast is needed. template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) + expected(const unexpected& e) noexcept; template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; - // Deleted for reference E with value G: the referent lives inside the unexpected - // object, so binding E& to it would dangle once a temporary source is destroyed. Use - // (unexpect, lvalue), or an unexpected holding an external object, instead. - template - requires(is_reference_v && !is_reference_v) - constexpr expected(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would " - "dangle — use unexpected"); + template constexpr expected(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected(unexpected&&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would " - "dangle — use unexpected"); + constexpr expected(unexpected&&) = delete; - // In-place constructor for error - template - requires(is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr explicit expected(unexpect_t, Args&&... args); + template constexpr explicit expected(unexpect_t, Args&&... args); - // Deleted: single argument would bind E& to a temporary — dangling prevention - template - requires(@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " - "temporary that dangles; pass an lvalue reference"); + template constexpr expected(unexpect_t, Args&&...) = delete; - // Deleted catch-all: reference E, argument neither constructible nor a dangling case template requires(is_reference_v && !is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = BEMAN_EXPECTED_DELETE_MSG( - "expected: no viable conversion from the given argument(s) to E&"); + constexpr expected(unexpect_t, Args&&...) = delete; - // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); template - requires is_reference_v - constexpr expected(unexpect_t, initializer_list, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG("expected: initializer-list error construction " - "cannot bind a reference; pass an lvalue reference"); + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; - // ------------------------------------------------------------------------- - // Destructor - // ------------------------------------------------------------------------- + constexpr ~expected() = default; - constexpr ~expected() - requires is_trivially_destructible_v - = default; + constexpr ~expected(); - constexpr ~expected() - requires(!is_trivially_destructible_v); + constexpr expected& operator=(const expected&) = default; - // ------------------------------------------------------------------------- - // Assignment (rebind semantics) - // ------------------------------------------------------------------------- + constexpr expected& operator=(const expected& rhs) noexcept( + is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); - // Copy assignment (trivial path) - constexpr expected& operator=(const expected&) - requires(is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v) - = default; + constexpr expected& operator=(expected&&) noexcept = default; - // Copy assignment (non-trivial path) - constexpr expected& operator=(const expected& rhs) noexcept( - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v) - requires((is_reference_v || - (is_copy_constructible_v && is_copy_assignable_v)) && - !(is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v)); - - // Move assignment (trivial path) - constexpr expected& operator=(expected&&) noexcept - requires(is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v) - = default; - - // Move assignment (non-trivial path) constexpr expected& operator=(expected&& rhs) noexcept( - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v) - requires((is_reference_v || - (is_move_constructible_v && is_move_assignable_v)) && - !(is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v)); + is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); - // Rebind reference from lvalue - template - requires(!is_same_v, expected> && - !@\exposidnc{is-unexpected-specialization}@>::value && - is_constructible_v && !reference_constructs_from_temporary_v) - constexpr expected& operator=(U&& u); + template constexpr expected& operator=(U&& u); - // Assignment from unexpected — value-E path - template - requires(!is_reference_v && is_constructible_v && - is_assignable_v) - constexpr expected& operator=(const unexpected& e); + template constexpr expected& operator=(const unexpected& e); - template - requires(!is_reference_v && is_constructible_v && is_assignable_v) - constexpr expected& operator=(unexpected&& e); + template constexpr expected& operator=(unexpected&& e); - // Rebinding assignment for reference E from reference G — binds unex_ to the external - // referent. - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(const unexpected& e); + template constexpr expected& operator=(const unexpected& e); - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(unexpected&& e); + template constexpr expected& operator=(unexpected&& e); - // Deleted for reference E with value G: would rebind E& to unexpected's temporary - // storage. - template - requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot assign from unexpected; the value would dangle — " - "use unexpected"); + template constexpr expected& operator=(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(unexpected&&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot assign from unexpected; the value would dangle — " - "use unexpected"); + constexpr expected& operator=(unexpected&&) = delete; - // emplace — rebind the reference template - requires(is_constructible_v && !reference_constructs_from_temporary_v) constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v); - // ------------------------------------------------------------------------- - // Swap - // ------------------------------------------------------------------------- - constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && (is_reference_v || - is_nothrow_swappable_v)) - requires((is_reference_v || is_swappable_v) && is_move_constructible_v); - - friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))) - requires((is_reference_v || is_swappable_v) && is_move_constructible_v); + is_nothrow_swappable_v)); - // ------------------------------------------------------------------------- - // Observers - // ------------------------------------------------------------------------- + friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))); constexpr T* operator->() const noexcept; constexpr T& operator*() const noexcept; @@ -3498,82 +2982,43 @@ constexpr T& value() const&; constexpr T& value() &&; - // error() — shallow const: always returns E& regardless of const on expected constexpr const E& error() const& noexcept; constexpr E& error() & noexcept; constexpr const E&& error() const&& noexcept; constexpr E&& error() && noexcept; - template> - requires(is_object_v && !is_array_v) - constexpr remove_cv_t value_or(U&& def) const; + template> constexpr remove_cv_t value_or(U&& def) const; - // Constraints spell error_value_type as its underlying trait expression rather than - // the member typedef: clang (through 22) fails to match an out-of-line constrained - // member of a partial specialization when the requires-clause names a member typedef - // of the class. template - requires(is_copy_constructible_v>> && - is_convertible_v>>) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; template - requires(is_move_constructible_v>> && - is_convertible_v>>) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; - // ------------------------------------------------------------------------- - // Monadic operations - // ------------------------------------------------------------------------- - - template - requires is_constructible_v - constexpr auto and_then(F&& f) &; - template - requires is_constructible_v - constexpr auto and_then(F&& f) &&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&&; + template 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&&; - // transform: f receives T& (value); error propagates as E; result is expected - template - requires is_constructible_v - constexpr auto transform(F&& f) &; - template - requires is_constructible_v - constexpr auto transform(F&& f) &&; - template - requires is_constructible_v - constexpr auto transform(F&& f) const&; - template - requires is_constructible_v - constexpr auto transform(F&& f) const&&; - - // transform_error: f receives E; value propagates as T&; result is expected + 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&&; - // ------------------------------------------------------------------------- - // Equality operators (hidden friends) - // ------------------------------------------------------------------------- - template - requires(!is_void_v) friend constexpr bool operator==(const expected& x, const expected& y); template - requires(!@\exposidnc{is-expected-specialization}@::value) friend constexpr bool operator==(const expected& x, const T2& val); template @@ -3589,27 +3034,25 @@ } \end{codeblock} -\begin{itemdescr} \pnum \mandates -A program that instantiates the definition of \tcode{expected} with an \tcode{E} that is not a valid template argument for \tcode{unexpected} is ill-formed. \tcode{T} shall be an object type that is not an array type, \tcode{in_place_t}, \tcode{unexpect_t}, or a specialization of \tcode{unexpected}. +A program that instantiates the definition of \tcode{expected} with an \tcode{E} that is not a valid template argument for \tcode{unexpected} is ill-formed. \tcode{T} shall be an object type that is not an array type, \tcode{in_place_t}, \tcode{unexpect_t}, or a specialization of \tcode{unexpected}. \pnum \remarks -An object of type \tcode{expected} either represents a reference to an object of type \tcode{T}, or holds an error. Member \tcode{has_val} indicates whether the object represents a reference. When it represents a reference, member \tcode{val} points to the referenced object, which is not owned by the \tcode{expected} object. Otherwise, the error is \tcode{unex.error()}. -\end{itemdescr} +An object of type \tcode{expected} either represents a reference to an object of type \tcode{T}, or holds an error. Member \tcode{has_val} indicates whether the object represents a reference. When it represents a reference, member \exposid{val} points to the referenced object, which is not owned by the \tcode{expected} object. Otherwise, the error is \tcode{\exposid{unex}.error()}. \rSec3[expected.ref.cons]{Constructors} \indexlibraryctor{expected}% \begin{itemdecl} -; +expected() = delete; \end{itemdecl} \begin{itemdescr} \pnum \remarks -\tcode{expected} has no default constructor: a reference cannot be null, so there is no empty state to default-construct into. +\tcode{expected} has no default constructor: a reference cannot be null, so there is no empty state to default-construct into. \end{itemdescr} \indexlibraryctor{expected}% @@ -3620,7 +3063,7 @@ \begin{itemdescr} \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, initializes \tcode{val} with \tcode{rhs.val}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \tcode{unex} with \tcode{rhs.unex}. +If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with \tcode{rhs.\exposid{val}}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \exposid{unex} with \tcode{rhs.\exposid{unex}}. \pnum \ensures @@ -3644,7 +3087,7 @@ \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, initializes \tcode{val} with \tcode{rhs.val}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \tcode{unex} with \tcode{rhs.unex}. +If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with \tcode{rhs.\exposid{val}}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \exposid{unex} with \tcode{rhs.\exposid{unex}}. \pnum \ensures @@ -3663,7 +3106,7 @@ \begin{itemdescr} \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, initializes \tcode{val} with \tcode{rhs.val}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \tcode{unex} with \tcode{std::move(rhs.unex)}. +If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with \tcode{rhs.\exposid{val}}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \exposid{unex} with \tcode{std::move(rhs.\exposid{unex})}. \pnum \ensures @@ -3676,30 +3119,30 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(in_place_t, Args&&...); +template + constexpr expected(in_place_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} \pnum \remarks -\tcode{expected} has no in-place value constructor: \tcode{T&} cannot be constructed in-place. Pass a \tcode{U} convertible to \tcode{T&} instead. +\tcode{expected} has no in-place value constructor: \tcode{T\&} cannot be constructed in-place. Pass a \tcode{U} convertible to \tcode{T\&} instead. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) - expected(U&& u) noexcept(is_nothrow_constructible_v); + constexpr explicit(!is_convertible_v) expected(U&& u) noexcept(is_nothrow_constructible_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{remove_cvref_t} is not \tcode{in_place_t}, \tcode{expected}, or a specialization of \tcode{unexpected}; \tcode{is_constructible_v} is \tcode{true}; and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\tcode{remove_cvref_t} is not \tcode{in_place_t}, \tcode{expected}, or a specialization of \tcode{unexpected}; \tcode{is_constructible_v} is \tcode{true}; and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \pnum \effects -Let \tcode{r} be the lvalue result of \tcode{T& r = std::forward(u);}. Initializes \tcode{val} with \tcode{addressof(r)}. +Let \tcode{r} be the lvalue result of \tcode{T\& r = std::forward(u);}. Initializes \exposid{val} with \tcode{addressof(r)}. \pnum \ensures @@ -3708,57 +3151,54 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(U&&); +template + constexpr expected(U&&) = delete; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{reference_constructs_from_temporary_v} is \tcode{true}. +\tcode{reference_constructs_from_temporary_v} is \tcode{true}. \pnum \remarks -A constructor for which \tcode{reference_constructs_from_temporary_v} is \tcode{true} — one that would bind \tcode{T&} to a temporary — is defined as deleted. +A constructor for which \tcode{reference_constructs_from_temporary_v} is \tcode{true} — one that would bind \tcode{T\&} to a temporary — is defined as deleted. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(const expected& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(expected&& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}; \tcode{reference_constructs_from_temporary_v} is \tcode{false}; and \tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}; \tcode{reference_constructs_from_temporary_v} is \tcode{false}; and \tcode{is_constructible_v} is \tcode{true}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, initializes \tcode{val} with \tcode{addressof(*rhs)}, so that \tcode{*this} refers to the object referred to by \tcode{rhs}; otherwise, initializes \tcode{unex} with the error of \tcode{rhs}. No object referred to by \tcode{rhs} is moved from. +If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with \tcode{addressof(*rhs)}, so that \tcode{*this} refers to the object referred to by \tcode{rhs}; otherwise, initializes \exposid{unex} with the error of \tcode{rhs}. No object referred to by \tcode{rhs} is moved from. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(const expected& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(expected&& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}; \tcode{reference_constructs_from_temporary_v} is \tcode{false}; \tcode{G} is a reference type; and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}; \tcode{reference_constructs_from_temporary_v} is \tcode{false}; \tcode{G} is a reference type; and \tcode{is_convertible_v} is \tcode{true}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, initializes \tcode{val} with \tcode{addressof(*rhs)}, so that \tcode{*this} refers to the object referred to by \tcode{rhs}; otherwise, initializes \tcode{unex} with the error of \tcode{rhs}. No object referred to by \tcode{rhs} is moved from. +If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with \tcode{addressof(*rhs)}, so that \tcode{*this} refers to the object referred to by \tcode{rhs}; otherwise, initializes \exposid{unex} with the error of \tcode{rhs}. No object referred to by \tcode{rhs} is moved from. \pnum \remarks @@ -3768,19 +3208,19 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e); + constexpr explicit(!is_convertible_v) expected(const unexpected& e); template -constexpr explicit(!is_convertible_v) expected(unexpected&& e); + constexpr explicit(!is_convertible_v) expected(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \effects -Initializes \tcode{unex} with the error of \tcode{e}. +Initializes \exposid{unex} with the error of \tcode{e}. \pnum \ensures @@ -3790,9 +3230,9 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; template -constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; + constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; \end{itemdecl} \begin{itemdescr} @@ -3802,7 +3242,7 @@ \pnum \effects -Initializes \tcode{unex} with the error of \tcode{e}. +Initializes \exposid{unex} with the error of \tcode{e}. \pnum \ensures @@ -3815,7 +3255,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -3825,12 +3266,13 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E\&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr explicit expected(unexpect_t, Args&&... args); +template + constexpr explicit expected(unexpect_t, Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -3840,7 +3282,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{in_place} and \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{in_place} and \tcode{std::forward(args)...}. \pnum \ensures @@ -3849,7 +3291,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -3859,23 +3302,23 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. +When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E\&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); + constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{in_place}, \tcode{il}, and \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{in_place}, \tcode{il}, and \tcode{std::forward(args)...}. \pnum \ensures @@ -3889,7 +3332,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -3935,7 +3378,7 @@ \pnum \effects -If \tcode{has_value()} is \tcode{false}, destroys \tcode{unex}. \tcode{T} is not destroyed; \tcode{*this} never owns the object it refers to. +If \tcode{has_value()} is \tcode{false}, destroys \exposid{unex}. \tcode{T} is not destroyed; \tcode{*this} never owns the object it refers to. \pnum \remarks @@ -3956,7 +3399,7 @@ \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.val} to \tcode{val}; otherwise destroys \tcode{unex} and initializes \tcode{val} with \tcode{rhs.val}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \tcode{unex}, as for the primary template. In every case \tcode{*this} comes to refer to the object \tcode{rhs} refers to, or to hold the error of \tcode{rhs}. +If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.\exposid{val}} to \exposid{val}; otherwise destroys \exposid{unex} and initializes \exposid{val} with \tcode{rhs.\exposid{val}}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \exposid{unex}, as for the primary template. In every case \tcode{*this} comes to refer to the object \tcode{rhs} refers to, or to hold the error of \tcode{rhs}. \pnum \returns @@ -3964,25 +3407,25 @@ \pnum \remarks -Assignment rebinds: assigning to an \tcode{expected} that holds a value changes which object it refers to. It never assigns through to the referent. This operator is trivial. +Assignment rebinds: assigning to an \tcode{expected} that holds a value changes which object it refers to. It never assigns through to the referent. This operator is trivial. \end{itemdescr} \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -constexpr expected& operator=(const expected& rhs) noexcept( - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); -constexpr expected& operator=(expected&& rhs) noexcept( - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); +constexpr expected& operator=(const expected& rhs) noexcept(is_nothrow_copy_constructible_v && + is_nothrow_copy_assignable_v); +constexpr expected& operator=(expected&& rhs) noexcept(is_nothrow_move_constructible_v && + is_nothrow_move_assignable_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v || (is_copy_constructible_v && is_copy_assignable_v)} is \tcode{true} and \tcode{(is_trivially_copy_constructible_v && is_trivially_copy_assignable_v && is_trivially_destructible_v)} is \tcode{false}. +\tcode{is_reference_v || (is_copy_constructible_v \&\& is_copy_assignable_v)} is \tcode{true} and \tcode{(is_trivially_copy_constructible_v \&\& is_trivially_copy_assignable_v \&\& is_trivially_destructible_v)} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.val} to \tcode{val}; otherwise destroys \tcode{unex} and initializes \tcode{val} with \tcode{rhs.val}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \tcode{unex}, as for the primary template. In every case \tcode{*this} comes to refer to the object \tcode{rhs} refers to, or to hold the error of \tcode{rhs}. +If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.\exposid{val}} to \exposid{val}; otherwise destroys \exposid{unex} and initializes \exposid{val} with \tcode{rhs.\exposid{val}}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \exposid{unex}, as for the primary template. In every case \tcode{*this} comes to refer to the object \tcode{rhs} refers to, or to hold the error of \tcode{rhs}. \pnum \returns @@ -4005,7 +3448,7 @@ \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.val} to \tcode{val}; otherwise destroys \tcode{unex} and initializes \tcode{val} with \tcode{rhs.val}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \tcode{unex}, as for the primary template. +If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.\exposid{val}} to \exposid{val}; otherwise destroys \exposid{unex} and initializes \exposid{val} with \tcode{rhs.\exposid{val}}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \exposid{unex}, as for the primary template. \pnum \returns @@ -4018,17 +3461,18 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(U&& u); +template + constexpr expected& operator=(U&& u); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{remove_cvref_t} is neither \tcode{expected} nor a specialization of \tcode{unexpected}, \tcode{is_constructible_v} is \tcode{true}, and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\tcode{remove_cvref_t} is neither \tcode{expected} nor a specialization of \tcode{unexpected}, \tcode{is_constructible_v} is \tcode{true}, and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \pnum \effects -Let \tcode{r} be the lvalue result of \tcode{T& r = std::forward(u);}. If \tcode{has_value()} is \tcode{true}, assigns \tcode{addressof(r)} to \tcode{val}. Otherwise, destroys \tcode{unex}, initializes \tcode{val} with \tcode{addressof(r)}, and sets \tcode{has_val} to \tcode{true}; if binding \tcode{r} throws, \tcode{*this} is left unchanged. +Let \tcode{r} be the lvalue result of \tcode{T\& r = std::forward(u);}. If \tcode{has_value()} is \tcode{true}, assigns \tcode{addressof(r)} to \exposid{val}. Otherwise, destroys \exposid{unex}, initializes \exposid{val} with \tcode{addressof(r)}, and sets \tcode{has_val} to \tcode{true}; if binding \tcode{r} throws, \tcode{*this} is left unchanged. \pnum \returns @@ -4037,18 +3481,20 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true} and \tcode{is_assignable_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true} and \tcode{is_assignable_v} is \tcode{true}. \pnum \effects -Makes \tcode{*this} hold the error of \tcode{e}, reinitializing \tcode{unex} from \tcode{e} rather than assigning through it. +Makes \tcode{*this} hold the error of \tcode{e}, reinitializing \exposid{unex} from \tcode{e} rather than assigning through it. \pnum \returns @@ -4057,8 +3503,10 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} @@ -4068,7 +3516,7 @@ \pnum \effects -Makes \tcode{*this} hold the error of \tcode{e}, reinitializing \tcode{unex} from \tcode{e} rather than assigning through it. \tcode{unex.error()} thereafter refers to the same object as \tcode{e.error()}; the previously referenced object, if any, is not modified. +Makes \tcode{*this} hold the error of \tcode{e}, reinitializing \exposid{unex} from \tcode{e} rather than assigning through it. \tcode{\exposid{unex}.error()} thereafter refers to the same object as \tcode{e.error()}; the previously referenced object, if any, is not modified. \pnum \returns @@ -4081,7 +3529,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -4091,27 +3540,27 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \tcode{unex} to \tcode{unexpected}'s temporary storage. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \exposid{unex} to \tcode{unexpected}'s temporary storage. \end{itemdescr} \indexlibrarymember{emplace}{expected}% \begin{itemdecl} template -constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v); + constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true} and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\tcode{is_constructible_v} is \tcode{true} and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \pnum \effects -Rebinds \tcode{*this} to refer to the object bound by \tcode{T& r = std::forward(u);}: if \tcode{has_value()} is \tcode{false}, destroys \tcode{unex} first. Sets \tcode{val} to \tcode{addressof(r)} and \tcode{has_val} to \tcode{true}. +Rebinds \tcode{*this} to refer to the object bound by \tcode{T\& r = std::forward(u);}: if \tcode{has_value()} is \tcode{false}, destroys \exposid{unex} first. Sets \exposid{val} to \tcode{addressof(r)} and \tcode{has_val} to \tcode{true}. \pnum \returns -\tcode{*val}. +\tcode{*\exposid{val}}. \end{itemdescr} \rSec3[expected.ref.swap]{Swap} @@ -4119,8 +3568,7 @@ \indexlibrarymember{swap}{expected}% \begin{itemdecl} constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && - (is_reference_v || - is_nothrow_swappable_v)); + (is_reference_v || is_nothrow_swappable_v)); \end{itemdecl} \begin{itemdescr} @@ -4130,11 +3578,11 @@ \pnum \effects -Exchanges the states of \tcode{*this} and \tcode{rhs}. When both hold values, exchanges \tcode{val} and \tcode{rhs.val} — the referenced objects are not swapped. Otherwise behaves as the primary template's \tcode{swap} does for the error. +Exchanges the states of \tcode{*this} and \tcode{rhs}. When both hold values, exchanges \exposid{val} and \tcode{rhs.\exposid{val}} — the referenced objects are not swapped. Otherwise behaves as the primary template's \tcode{swap} does for the error. \pnum \remarks -The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v && (is_reference_v || is_nothrow_swappable_v)}. +The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v \&\& (is_reference_v || is_nothrow_swappable_v)}. \end{itemdescr} \indexlibraryglobal{swap}% @@ -4166,11 +3614,11 @@ \pnum \returns -\tcode{val}. +\exposid{val}. \pnum \remarks -This is a \tcode{const} member function that returns a non-\tcode{const} \tcode{T*}; the constness of \tcode{*this} does not propagate to the referenced object. For deep \tcode{const}, use \tcode{expected}. +This is a \tcode{const} member function that returns a non-\tcode{const} \tcode{T*}; the constness of \tcode{*this} does not propagate to the referenced object. For deep \tcode{const}, use \tcode{expected}. \end{itemdescr} \indexlibrarymember{operator*}{expected}% @@ -4185,11 +3633,11 @@ \pnum \returns -\tcode{*val}. +\tcode{*\exposid{val}}. \pnum \remarks -This is a \tcode{const} member function that returns a non-\tcode{const} \tcode{T&}; the constness of \tcode{*this} does not propagate to the referenced object. For deep \tcode{const}, use \tcode{expected}. +This is a \tcode{const} member function that returns a non-\tcode{const} \tcode{T\&}; the constness of \tcode{*this} does not propagate to the referenced object. For deep \tcode{const}, use \tcode{expected}. \end{itemdescr} \indexlibrarymember{operator bool}{expected}% @@ -4217,7 +3665,7 @@ \pnum \returns -\tcode{*val} if \tcode{has_value()} is \tcode{true}. +\tcode{*\exposid{val}} if \tcode{has_value()} is \tcode{true}. \pnum \throws @@ -4232,7 +3680,7 @@ \begin{itemdescr} \pnum \returns -\tcode{*val} if \tcode{has_value()} is \tcode{true}. +\tcode{*\exposid{val}} if \tcode{has_value()} is \tcode{true}. \pnum \throws @@ -4252,7 +3700,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -4268,12 +3716,13 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{value_or}{expected}% \begin{itemdecl} -template> constexpr remove_cv_t value_or(U&& def) const; +template> + constexpr remove_cv_t value_or(U&& def) const; \end{itemdecl} \begin{itemdescr} @@ -4283,17 +3732,17 @@ \pnum \mandates -\tcode{is_convertible_v>} and \tcode{is_convertible_v>} are \tcode{true}. +\tcode{is_convertible_v>} and \tcode{is_convertible_v>} are \tcode{true}. \pnum \returns -\tcode{has_value() ? static_cast>(*val) : static_cast>(std::forward(def))}. The result is an object, never a reference. +\tcode{has_value() ? static_cast>(*\exposid{val}) : static_cast>(std::forward(def))}. The result is an object, never a reference. \end{itemdescr} \indexlibrarymember{error_or}{expected}% \begin{itemdecl} template -constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; \end{itemdecl} \begin{itemdescr} @@ -4308,7 +3757,8 @@ \indexlibrarymember{error_or}{expected}% \begin{itemdecl} -template constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; +template + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; \end{itemdecl} \begin{itemdescr} @@ -4325,8 +3775,10 @@ \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &; -template constexpr auto and_then(F&& f) const&; +template + constexpr auto and_then(F&& f) &; +template + constexpr auto and_then(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -4336,21 +3788,23 @@ \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), *val); else return U(unexpect, error());} where \tcode{U} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), *\exposid{val}); else return U(unexpect, error());} where \tcode{U} is \tcode{remove_cvref_t>}. \pnum \remarks -The member templates \tcode{and_then}, \tcode{or_else}, \tcode{transform}, and \tcode{transform_error} behave as specified for the primary template, with one difference: the value is passed to the callable as \tcode{T&} for every ref-qualification of \tcode{*this}. An rvalue \tcode{expected} does not pass its referent as an rvalue; the object referred to is never moved from by these operations. +The member templates \tcode{and_then}, \tcode{or_else}, \tcode{transform}, and \tcode{transform_error} behave as specified for the primary template, with one difference: the value is passed to the callable as \tcode{T\&} for every ref-qualification of \tcode{*this}. An rvalue \tcode{expected} does not pass its referent as an rvalue; the object referred to is never moved from by these operations. \end{itemdescr} \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &&; -template constexpr auto and_then(F&& f) const&&; +template + constexpr auto and_then(F&& f) &&; +template + constexpr auto and_then(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -4360,49 +3814,55 @@ \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), *val); else return U(unexpect, std::move(error()));} where \tcode{U} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), *\exposid{val}); else return U(unexpect, std::move(error()));} where \tcode{U} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &; -template constexpr auto or_else(F&& f) const&; +template + constexpr auto or_else(F&& f) &; +template + constexpr auto or_else(F&& f) const&; \end{itemdecl} \begin{itemdescr} \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{value_type} is the same type as \tcode{T&}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{value_type} is the same type as \tcode{T\&}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(*val); else return invoke(std::forward(f), error());} where \tcode{G} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return G(*\exposid{val}); else return invoke(std::forward(f), error());} where \tcode{G} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &&; -template constexpr auto or_else(F&& f) const&&; +template + constexpr auto or_else(F&& f) &&; +template + constexpr auto or_else(F&& f) const&&; \end{itemdecl} \begin{itemdescr} \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{value_type} is the same type as \tcode{T&}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{value_type} is the same type as \tcode{T\&}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(*val); else return invoke(std::forward(f), std::move(error()));} where \tcode{G} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return G(*\exposid{val}); else return invoke(std::forward(f), std::move(error()));} where \tcode{G} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &; -template constexpr auto transform(F&& f) const&; +template + constexpr auto transform(F&& f) &; +template + constexpr auto transform(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -4412,13 +3872,15 @@ \pnum \effects -Equivalent to: \tcode{if (!has_value()) return U(unexpect, error()); else return expected(in_place, invoke(std::forward(f), *val));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. +Equivalent to: \tcode{if (!has_value()) return U(unexpect, error()); else return expected(in_place, invoke(std::forward(f), *\exposid{val}));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &&; -template constexpr auto transform(F&& f) const&&; +template + constexpr auto transform(F&& f) &&; +template + constexpr auto transform(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -4428,13 +3890,15 @@ \pnum \effects -Equivalent to: \tcode{if (!has_value()) return U(unexpect, std::move(error())); else return expected(in_place, invoke(std::forward(f), *val));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. +Equivalent to: \tcode{if (!has_value()) return U(unexpect, std::move(error())); else return expected(in_place, invoke(std::forward(f), *\exposid{val}));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &; -template constexpr auto transform_error(F&& f) const&; +template + constexpr auto transform_error(F&& f) &; +template + constexpr auto transform_error(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -4449,13 +3913,15 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(*val); else return expected(unexpect, invoke(std::forward(f), error()));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. +Equivalent to: \tcode{if (has_value()) return G(*\exposid{val}); else return expected(unexpect, invoke(std::forward(f), error()));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &&; -template constexpr auto transform_error(F&& f) const&&; +template + constexpr auto transform_error(F&& f) &&; +template + constexpr auto transform_error(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -4470,7 +3936,7 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(*val); else return expected(unexpect, invoke(std::forward(f), std::move(error())));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. +Equivalent to: \tcode{if (has_value()) return G(*\exposid{val}); else return expected(unexpect, invoke(std::forward(f), std::move(error())));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. \end{itemdescr} \rSec3[expected.ref.eq]{Equality operators} @@ -4478,7 +3944,7 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const expected& y); + friend constexpr bool operator==(const expected& x, const expected& y); \end{itemdecl} \begin{itemdescr} @@ -4501,7 +3967,8 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} -template friend constexpr bool operator==(const expected& x, const T2& val); +template + friend constexpr bool operator==(const expected& x, const T2& val); \end{itemdecl} \begin{itemdescr} @@ -4515,13 +3982,13 @@ \pnum \returns -\tcode{x.has_value() && static_cast(*x == val)}. +\tcode{x.has_value() \&\& static_cast(*x == val)}. \end{itemdescr} \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const unexpected& e); + friend constexpr bool operator==(const expected& x, const unexpected& e); \end{itemdecl} \begin{itemdescr} @@ -4531,5 +3998,5 @@ \pnum \returns -\tcode{!x.has_value() && static_cast(x.error() == e.error())}. +\tcode{!x.has_value() \&\& static_cast(x.error() == e.error())}. \end{itemdescr} diff --git a/papers/wording/fragments/expected.bad.tex b/papers/wording/fragments/expected.bad.tex index a88375d..0adc951 100644 --- a/papers/wording/fragments/expected.bad.tex +++ b/papers/wording/fragments/expected.bad.tex @@ -29,11 +29,9 @@ } \end{codeblock} -\begin{itemdescr} \pnum \remarks The class template \tcode{bad_expected_access} defines the type of objects thrown as exceptions to report the situation where an attempt is made to access the value of an \tcode{expected} object for which \tcode{has_value()} is \tcode{false}. -\end{itemdescr} \indexlibraryctor{bad_expected_access}% \begin{itemdecl} @@ -87,7 +85,7 @@ \begin{itemdescr} \pnum \returns -\tcode{std::move(unex)}. +\tcode{std::move(\exposid{unex})}. \end{itemdescr} \indexlibrarymember{error}{bad_expected_access}% @@ -98,5 +96,5 @@ \begin{itemdescr} \pnum \returns -\tcode{std::move(unex)}. +\tcode{std::move(\exposid{unex})}. \end{itemdescr} diff --git a/papers/wording/fragments/expected.expected.tex b/papers/wording/fragments/expected.expected.tex index b106da0..10b88f6 100644 --- a/papers/wording/fragments/expected.expected.tex +++ b/papers/wording/fragments/expected.expected.tex @@ -16,310 +16,120 @@ template using rebind = expected; - // ------------------------------------------------------------------------- - // [expected.object.cons] Constructors - // ------------------------------------------------------------------------- - - // Default constructor: value-initializes T - constexpr expected() noexcept(is_nothrow_default_constructible_v) - requires is_default_constructible_v; - - // Copy constructor (trivial path). Unconstrained on purpose: this is the - // sole declaration when T or E is not copy constructible at all (it is - // then implicitly defined as deleted), and the more-constrained - // non-trivial-path overload below is selected over it by constraint - // subsumption whenever it is viable. + constexpr expected() noexcept(is_nothrow_default_constructible_v); + constexpr expected(const expected&) = default; - // Copy constructor (non-trivial path) - constexpr expected(const expected& rhs) noexcept(is_nothrow_copy_constructible_v && - is_nothrow_copy_constructible_v) - requires(is_copy_constructible_v && is_copy_constructible_v && - !(is_trivially_copy_constructible_v && - is_trivially_copy_constructible_v)); + constexpr expected(const expected& rhs) noexcept( + is_nothrow_copy_constructible_v && is_nothrow_copy_constructible_v); - // Move constructor (trivial path). Unconstrained; see the copy - // constructor above for why. No explicit noexcept: let the compiler - // deduce it, so a non-movable-at-all E deletes rather than mismatches. constexpr expected(expected&&) = default; - // Move constructor (non-trivial path) constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v && - is_nothrow_move_constructible_v) - requires(is_move_constructible_v && is_move_constructible_v && - !(is_trivially_move_constructible_v && - is_trivially_move_constructible_v)); + is_nothrow_move_constructible_v); - // Converting copy constructor from expected — value-E path template - requires(!is_reference_v && is_constructible_v && - is_constructible_v && - (is_same_v> || - !@\exposidnc{converts-from-any-cvref}@>) && - !is_constructible_v, expected&> && - !is_constructible_v, expected&&> && - !is_constructible_v, const expected&> && - !is_constructible_v, const expected&&>) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); - // Converting move constructor from expected — value-E path template - requires(!is_reference_v && is_constructible_v && - is_constructible_v && - (is_same_v> || - !@\exposidnc{converts-from-any-cvref}@>) && - !is_constructible_v, expected&> && - !is_constructible_v, expected&&> && - !is_constructible_v, const expected&> && - !is_constructible_v, const expected&&>) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); - // Converting constructor from expected — reference-E path: only accepts sources - // whose error type G is itself a reference convertible to E. template - requires(is_reference_v && is_reference_v && - is_constructible_v && is_convertible_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); template - requires(is_reference_v && is_reference_v && is_constructible_v && - is_convertible_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); - // Constructor from value U&& template> - requires(!is_same_v, in_place_t> && - !is_same_v, unexpect_t> && - !is_same_v, expected> && is_constructible_v && - !@\exposidnc{is-unexpected-specialization}@>::value && - (!is_same_v> || - !@\exposidnc{is-expected-specialization}@>::value)) constexpr explicit(!is_convertible_v) expected(U&& v); - // Constructor from unexpected const& / && — value-E path template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(const unexpected& e); template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e); - // Constructor from unexpected — reference-E path. Allowed only when G is itself a - // reference, i.e. the source unexpected holds a reference to an external object, so - // binding E& to e.error() cannot dangle regardless of the source's value category. No - // const_cast is needed. template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) + expected(const unexpected& e) noexcept; template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; - // Deleted for reference E with value G: the referent lives inside the unexpected - // object, so binding E& to it would dangle once a temporary source is destroyed. Use - // (unexpect, lvalue), or an unexpected holding an external object, instead. - template - requires(is_reference_v && !is_reference_v) - constexpr expected(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would dangle " - "— use unexpected"); + template constexpr expected(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected(unexpected&&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would dangle " - "— use unexpected"); + constexpr expected(unexpected&&) = delete; - // In-place constructor for value - template - requires is_constructible_v - constexpr explicit expected(in_place_t, Args&&... args); + template constexpr explicit expected(in_place_t, Args&&... args); - // In-place constructor for value with initializer_list template - requires is_constructible_v&, Args...> constexpr explicit expected(in_place_t, initializer_list il, Args&&... args); - // In-place constructor for error - template - requires(is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr explicit expected(unexpect_t, Args&&... args); + template constexpr explicit expected(unexpect_t, Args&&... args); - // Deleted: single argument would bind E& to a temporary — dangling prevention - template - requires(@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " - "temporary that dangles; pass an lvalue reference"); + template constexpr expected(unexpect_t, Args&&...) = delete; - // Deleted catch-all: reference E, argument neither constructible nor a dangling case - // (e.g. binding a non-const E& from a const lvalue). template requires(is_reference_v && !is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = BEMAN_EXPECTED_DELETE_MSG( - "expected: no viable conversion from the given argument(s) to E&"); + constexpr expected(unexpect_t, Args&&...) = delete; - // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); template - requires is_reference_v - constexpr expected(unexpect_t, initializer_list, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG("expected: initializer-list error construction " - "cannot bind a reference; pass an lvalue reference"); - - // ------------------------------------------------------------------------- - // [expected.object.dtor] Destructor - // ------------------------------------------------------------------------- - - constexpr ~expected() - requires(is_trivially_destructible_v && is_trivially_destructible_v) - = default; - - constexpr ~expected() - requires(!(is_trivially_destructible_v && is_trivially_destructible_v)); - - // ------------------------------------------------------------------------- - // [expected.object.assign] Assignment - // ------------------------------------------------------------------------- - - // Copy assignment (trivial path) - constexpr expected& operator=(const expected&) - requires(is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v && - is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v) - = default; - - // Copy assignment (non-trivial path) + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; + + constexpr ~expected() = default; + + constexpr ~expected(); + + constexpr expected& operator=(const expected&) = default; + constexpr expected& operator=(const expected& rhs) noexcept( is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v && - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v) - requires(is_copy_constructible_v && is_copy_assignable_v && - (is_reference_v || - (is_copy_constructible_v && is_copy_assignable_v)) && - (is_nothrow_move_constructible_v || - is_nothrow_move_constructible_v) && - !(is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v && - is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v)); - - // Move assignment (trivial path) - constexpr expected& operator=(expected&&) noexcept - requires(is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v && - is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v) - = default; - - // Move assignment (non-trivial path) + is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); + + constexpr expected& operator=(expected&&) noexcept = default; + constexpr expected& operator=(expected&& rhs) noexcept( is_nothrow_move_constructible_v && is_nothrow_move_assignable_v && - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v) - requires(is_move_constructible_v && is_move_assignable_v && - (is_reference_v || - (is_move_constructible_v && is_move_assignable_v)) && - (is_nothrow_move_constructible_v || - is_nothrow_move_constructible_v) && - !(is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v && - is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v)); - - // Assignment from value U&& - template> - requires(!is_same_v> && - !@\exposidnc{is-unexpected-specialization}@>::value && - is_constructible_v && is_assignable_v && - (is_nothrow_constructible_v || is_nothrow_move_constructible_v || - is_nothrow_move_constructible_v)) - constexpr expected& operator=(U&& v); - - // Assignment from unexpected — value-E path - template - requires(!is_reference_v && is_constructible_v && - is_assignable_v && - (is_nothrow_constructible_v || - is_nothrow_move_constructible_v || is_nothrow_move_constructible_v)) - constexpr expected& operator=(const unexpected& e); + is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); - template - requires(!is_reference_v && is_constructible_v && is_assignable_v && - (is_nothrow_constructible_v || is_nothrow_move_constructible_v || - is_nothrow_move_constructible_v)) - constexpr expected& operator=(unexpected&& e); - - // Rebinding assignment for reference E from reference G — binds unex_ to the external - // referent (never dangles; pointer store is noexcept). Mirrors the reference-E - // constructor. - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(const unexpected& e); + template> constexpr expected& operator=(U&& v); - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(unexpected&& e); + template constexpr expected& operator=(const unexpected& e); - // Deleted for reference E with value G: would rebind E& to unexpected's temporary - // storage. - template - requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(const unexpected&) = - BEMAN_EXPECTED_DELETE_MSG("expected: cannot assign from unexpected; " - "the value would dangle — use unexpected"); + template constexpr expected& operator=(unexpected&& e); + + template constexpr expected& operator=(const unexpected& e); + + template constexpr expected& operator=(unexpected&& e); + + template constexpr expected& operator=(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(unexpected&&) = - BEMAN_EXPECTED_DELETE_MSG("expected: cannot assign from unexpected; " - "the value would dangle — use unexpected"); + constexpr expected& operator=(unexpected&&) = delete; - // Emplace: destroy current value/error, construct value in-place - template - requires is_nothrow_constructible_v - constexpr T& emplace(Args&&... args) noexcept; + template constexpr T& emplace(Args&&... args) noexcept; template - requires is_nothrow_constructible_v&, Args...> constexpr T& emplace(initializer_list il, Args&&... args) noexcept; - // ------------------------------------------------------------------------- - // [expected.object.swap] Swap - // ------------------------------------------------------------------------- - constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && is_nothrow_swappable_v && is_nothrow_move_constructible_v && (is_reference_v || - is_nothrow_swappable_v)) - requires(is_swappable_v && (is_reference_v || is_swappable_v) && - is_move_constructible_v && is_move_constructible_v && - (is_nothrow_move_constructible_v || is_nothrow_move_constructible_v)) - ; - - friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))) - requires(is_swappable_v && (is_reference_v || is_swappable_v) && - is_move_constructible_v && is_move_constructible_v && - (is_nothrow_move_constructible_v || is_nothrow_move_constructible_v)) - ; - - // ------------------------------------------------------------------------- - // [expected.object.obs] Observers - // ------------------------------------------------------------------------- + is_nothrow_swappable_v)); + + friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))); constexpr const T* operator->() const noexcept; constexpr T* operator->() noexcept; @@ -347,81 +157,35 @@ template> constexpr T value_or(U&& def) &&; template - requires(is_copy_constructible_v<@\exposidnc{error-value-type}@> && - is_convertible_v) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; template - requires(is_move_constructible_v<@\exposidnc{error-value-type}@> && - is_convertible_v) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; - // ------------------------------------------------------------------------- - // [expected.object.monadic] Monadic operations - // ------------------------------------------------------------------------- - - template - requires is_constructible_v - constexpr auto and_then(F&& f) &; - template - requires is_constructible_v - constexpr auto and_then(F&& f) &&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&&; - - template - requires is_constructible_v - constexpr auto or_else(F&& f) &; - template - requires is_constructible_v - constexpr auto or_else(F&& f) &&; - template - requires is_constructible_v - constexpr auto or_else(F&& f) const&; - template - requires is_constructible_v - constexpr auto or_else(F&& f) const&&; - - template - requires is_constructible_v - constexpr auto transform(F&& f) &; - template - requires is_constructible_v - constexpr auto transform(F&& f) &&; - template - requires is_constructible_v - constexpr auto transform(F&& f) const&; - template - requires is_constructible_v - constexpr auto transform(F&& f) const&&; - - template - requires is_constructible_v - constexpr auto transform_error(F&& f) &; - template - requires is_constructible_v - constexpr auto transform_error(F&& f) &&; - template - requires is_constructible_v - constexpr auto transform_error(F&& f) const&; - template - requires is_constructible_v - constexpr auto transform_error(F&& f) const&&; - - // ------------------------------------------------------------------------- - // [expected.object.eq] Equality operators (hidden friends) - // ------------------------------------------------------------------------- + template 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&&; template - requires(!is_void_v) friend constexpr bool operator==(const expected& x, const expected& y); template - requires(!@\exposidnc{is-expected-specialization}@::value) friend constexpr bool operator==(const expected& x, const T2& val); template @@ -437,15 +201,13 @@ } \end{codeblock} -\begin{itemdescr} \pnum \mandates A program that instantiates the definition of \tcode{expected} with a \tcode{T} that is not a valid value type for \tcode{expected} (that is, \tcode{remove_cv_t} is \tcode{void}, or a complete non-array object type other than \tcode{in_place_t}, \tcode{unexpect_t}, or a specialization of \tcode{unexpected}) is ill-formed. A program that instantiates the definition of \tcode{expected} with an \tcode{E} that is not a valid template argument for \tcode{unexpected} is ill-formed. \pnum \remarks -Any object of type \tcode{expected} either contains a value of type \tcode{T} or a value of type \tcode{E} nested within it. Member \tcode{has_val} indicates whether the \tcode{expected} object contains an object of type \tcode{T}. When \tcode{has_value()} is \tcode{false}, the error is \tcode{unex.error()}. The error is held as an \tcode{unexpected}, and not as an \tcode{E}, so that \tcode{E} may be an lvalue reference type: an \tcode{E&} cannot be a union member, whereas \tcode{unexpected} holds a pointer to an external object. -\end{itemdescr} +Any object of type \tcode{expected} either contains a value of type \tcode{T} or a value of type \tcode{E} nested within it. Member \tcode{has_val} indicates whether the \tcode{expected} object contains an object of type \tcode{T}. When \tcode{has_value()} is \tcode{false}, the error is \tcode{\exposid{unex}.error()}. The error is held as an \tcode{unexpected}, and not as an \tcode{E}, so that \tcode{E} may be an lvalue reference type: an \tcode{E\&} cannot be a union member, whereas \tcode{unexpected} holds a pointer to an external object. \rSec3[expected.object.cons]{Constructors} @@ -461,7 +223,7 @@ \pnum \effects -Value-initializes \tcode{val}. +Value-initializes \exposid{val}. \pnum \ensures @@ -469,7 +231,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val}. +Any exception thrown by the initialization of \exposid{val}. \end{itemdescr} \indexlibraryctor{expected}% @@ -480,7 +242,7 @@ \begin{itemdescr} \pnum \effects -Direct-non-list-initializes \tcode{val} or \tcode{unex} (matching \tcode{rhs}'s active member) by trivial copy construction. +Direct-non-list-initializes \exposid{val} or \exposid{unex} (matching \tcode{rhs}'s active member) by trivial copy construction. \pnum \ensures @@ -500,11 +262,11 @@ \begin{itemdescr} \pnum \constraints -\tcode{is_copy_constructible_v} is \tcode{true}, \tcode{is_copy_constructible_v} is \tcode{true}, and \tcode{(is_trivially_copy_constructible_v && is_trivially_copy_constructible_v)} is \tcode{false}. +\tcode{is_copy_constructible_v} is \tcode{true}, \tcode{is_copy_constructible_v} is \tcode{true}, and \tcode{(is_trivially_copy_constructible_v \&\& is_trivially_copy_constructible_v)} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, direct-non-list-initializes \tcode{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()} is \tcode{true}, direct-non-list-initializes \exposid{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -512,7 +274,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val} or \tcode{unex}. +Any exception thrown by the initialization of \exposid{val} or \exposid{unex}. \pnum \remarks @@ -527,7 +289,7 @@ \begin{itemdescr} \pnum \effects -Direct-non-list-initializes \tcode{val} or \tcode{unex} (matching \tcode{rhs}'s active member) by trivial move construction. +Direct-non-list-initializes \exposid{val} or \exposid{unex} (matching \tcode{rhs}'s active member) by trivial move construction. \pnum \ensures @@ -540,18 +302,17 @@ \indexlibraryctor{expected}% \begin{itemdecl} -constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v && - is_nothrow_move_constructible_v); +constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v && is_nothrow_move_constructible_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_move_constructible_v} is \tcode{true}, \tcode{is_move_constructible_v} is \tcode{true}, and \tcode{(is_trivially_move_constructible_v && is_trivially_move_constructible_v)} is \tcode{false}. +\tcode{is_move_constructible_v} is \tcode{true}, \tcode{is_move_constructible_v} is \tcode{true}, and \tcode{(is_trivially_move_constructible_v \&\& is_trivially_move_constructible_v)} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, direct-non-list-initializes \tcode{val} with \tcode{std::move(*rhs)}. Otherwise, direct-non-list-initializes \tcode{unex} with \tcode{std::move(rhs.error())}. +If \tcode{rhs.has_value()} is \tcode{true}, direct-non-list-initializes \exposid{val} with \tcode{std::move(*rhs)}. Otherwise, direct-non-list-initializes \exposid{unex} with \tcode{std::move(rhs.error())}. \pnum \ensures @@ -559,7 +320,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val} or \tcode{unex}. +Any exception thrown by the initialization of \exposid{val} or \exposid{unex}. \pnum \remarks @@ -569,21 +330,20 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(const expected& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) + expected(const expected& rhs); template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(expected&& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_constructible_v} is \tcode{true}; and if \tcode{T} is not \tcode{bool}, \tcode{converts-from-any-cvref>} is \tcode{false}; and \tcode{is_constructible_v, expected&>} is \tcode{false}; and \tcode{is_constructible_v, expected>} is \tcode{false}; and \tcode{is_constructible_v, const expected&>} is \tcode{false}; and \tcode{is_constructible_v, const expected>} is \tcode{false}. +\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_constructible_v} is \tcode{true}; and if \tcode{T} is not \tcode{bool}, \tcode{converts-from-any-cvref>} is \tcode{false}; and \tcode{is_constructible_v, expected\&>} is \tcode{false}; and \tcode{is_constructible_v, expected>} is \tcode{false}; and \tcode{is_constructible_v, const expected\&>} is \tcode{false}; and \tcode{is_constructible_v, const expected>} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()}, direct-non-list-initializes \tcode{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()}, direct-non-list-initializes \exposid{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -591,27 +351,25 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val} or \tcode{unex}. +Any exception thrown by the initialization of \exposid{val} or \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(const expected& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(expected&& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_reference_v} is \tcode{true}; and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_reference_v} is \tcode{true}; and \tcode{is_convertible_v} is \tcode{true}. \pnum \effects -If \tcode{rhs.has_value()}, direct-non-list-initializes \tcode{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()}, direct-non-list-initializes \exposid{val} with \tcode{*rhs}. Otherwise, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -619,7 +377,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val} or \tcode{unex}. +Any exception thrown by the initialization of \exposid{val} or \exposid{unex}. \pnum \remarks @@ -629,7 +387,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template> -constexpr explicit(!is_convertible_v) expected(U&& v); + constexpr explicit(!is_convertible_v) expected(U&& v); \end{itemdecl} \begin{itemdescr} @@ -639,7 +397,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{val} with \tcode{std::forward(v)}. +Direct-non-list-initializes \exposid{val} with \tcode{std::forward(v)}. \pnum \ensures @@ -647,25 +405,25 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val}. +Any exception thrown by the initialization of \exposid{val}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e); + constexpr explicit(!is_convertible_v) expected(const unexpected& e); template -constexpr explicit(!is_convertible_v) expected(unexpected&& e); + constexpr explicit(!is_convertible_v) expected(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(e.error())}. +Direct-non-list-initializes \exposid{unex} with \tcode{std::forward(e.error())}. \pnum \ensures @@ -673,15 +431,15 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; template -constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; + constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; \end{itemdecl} \begin{itemdescr} @@ -691,7 +449,7 @@ \pnum \effects -Initializes \tcode{unex} with \tcode{e.error()}. +Initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -704,7 +462,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -714,12 +473,13 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E\&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr explicit expected(in_place_t, Args&&... args); +template + constexpr explicit expected(in_place_t, Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -729,7 +489,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{val} with \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{val} with \tcode{std::forward(args)...}. \pnum \ensures @@ -737,23 +497,23 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val}. +Any exception thrown by the initialization of \exposid{val}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit expected(in_place_t, initializer_list il, Args&&... args); + constexpr explicit expected(in_place_t, initializer_list il, Args&&... args); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{val} with \tcode{il, std::forward(args)...}. +Direct-non-list-initializes \exposid{val} with \tcode{il, std::forward(args)...}. \pnum \ensures @@ -761,12 +521,13 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{val}. +Any exception thrown by the initialization of \exposid{val}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr explicit expected(unexpect_t, Args&&... args); +template + constexpr explicit expected(unexpect_t, Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -776,7 +537,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{std::forward(args)...}. \pnum \ensures @@ -784,12 +545,13 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -799,23 +561,23 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. +When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E\&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); + constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{il, std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{il, std::forward(args)...}. \pnum \ensures @@ -823,7 +585,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \pnum \remarks @@ -833,7 +595,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -860,7 +622,7 @@ \pnum \effects -None: \tcode{val} or \tcode{unex} (whichever is active) has a trivial destructor. +None: \exposid{val} or \exposid{unex} (whichever is active) has a trivial destructor. \pnum \remarks @@ -875,11 +637,11 @@ \begin{itemdescr} \pnum \constraints -\tcode{(is_trivially_destructible_v && is_trivially_destructible_v)} is \tcode{false}. +\tcode{(is_trivially_destructible_v \&\& is_trivially_destructible_v)} is \tcode{false}. \pnum \effects -If \tcode{has_value()} is \tcode{true}, destroys \tcode{val}, otherwise destroys \tcode{unex}. +If \tcode{has_value()} is \tcode{true}, destroys \exposid{val}, otherwise destroys \exposid{unex}. \end{itemdescr} \rSec3[expected.object.assign]{Assignment} @@ -916,9 +678,10 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -constexpr expected& operator=(const expected& rhs) noexcept( - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v && - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); +constexpr expected& operator=(const expected& rhs) noexcept(is_nothrow_copy_constructible_v && + is_nothrow_copy_assignable_v && + is_nothrow_copy_constructible_v && + is_nothrow_copy_assignable_v); \end{itemdecl} \begin{itemdescr} @@ -927,14 +690,14 @@ \begin{itemize} \item \tcode{is_copy_constructible_v} is \tcode{true}, \item \tcode{is_copy_assignable_v} is \tcode{true}, -\item \tcode{is_reference_v || (is_copy_constructible_v && is_copy_assignable_v)} is \tcode{true}, +\item \tcode{is_reference_v || (is_copy_constructible_v \&\& is_copy_assignable_v)} is \tcode{true}, \item \tcode{is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}, -\item \tcode{(is_trivially_copy_constructible_v && is_trivially_copy_assignable_v && is_trivially_destructible_v && is_trivially_copy_constructible_v && is_trivially_copy_assignable_v && is_trivially_destructible_v)} is \tcode{false}. +\item \tcode{(is_trivially_copy_constructible_v \&\& is_trivially_copy_assignable_v \&\& is_trivially_destructible_v \&\& is_trivially_copy_constructible_v \&\& is_trivially_copy_assignable_v \&\& is_trivially_destructible_v)} is \tcode{false}. \end{itemize} \pnum \effects -If \tcode{this->has_value() && rhs.has_value()}, equivalent to \tcode{val = *rhs}. Otherwise, if \tcode{this->has_value()}, equivalent to \tcode{reinit-expected(unex, val, rhs.error())}. Otherwise, if \tcode{rhs.has_value()}, equivalent to \tcode{reinit-expected(val, unex, *rhs)}. Otherwise, equivalent to \tcode{unex = rhs.unex}. Then, if no exception was thrown, equivalent to: \tcode{has_val = rhs.has_value(); return *this;} When \tcode{E} is an lvalue reference type, each of the cases above that initializes or assigns \tcode{unex} rebinds it: \tcode{unex} comes to refer to the same object as \tcode{rhs}'s error. No previously or subsequently referenced object is assigned through. +If \tcode{this->has_value() \&\& rhs.has_value()}, equivalent to \tcode{\exposid{val} = *rhs}. Otherwise, if \tcode{this->has_value()}, equivalent to \tcode{reinit-expected(\exposid{unex}, \exposid{val}, rhs.error())}. Otherwise, if \tcode{rhs.has_value()}, equivalent to \tcode{reinit-expected(\exposid{val}, \exposid{unex}, *rhs)}. Otherwise, equivalent to \tcode{\exposid{unex} = rhs.\exposid{unex}}. Then, if no exception was thrown, equivalent to: \tcode{has_val = rhs.has_value(); return *this;} When \tcode{E} is an lvalue reference type, each of the cases above that initializes or assigns \exposid{unex} rebinds it: \exposid{unex} comes to refer to the same object as \tcode{rhs}'s error. No previously or subsequently referenced object is assigned through. \pnum \returns @@ -977,9 +740,10 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -constexpr expected& operator=(expected&& rhs) noexcept( - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v && - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); +constexpr expected& operator=(expected&& rhs) noexcept(is_nothrow_move_constructible_v && + is_nothrow_move_assignable_v && + is_nothrow_move_constructible_v && + is_nothrow_move_assignable_v); \end{itemdecl} \begin{itemdescr} @@ -988,14 +752,14 @@ \begin{itemize} \item \tcode{is_move_constructible_v} is \tcode{true}, \item \tcode{is_move_assignable_v} is \tcode{true}, -\item \tcode{is_reference_v || (is_move_constructible_v && is_move_assignable_v)} is \tcode{true}, +\item \tcode{is_reference_v || (is_move_constructible_v \&\& is_move_assignable_v)} is \tcode{true}, \item \tcode{is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}, -\item \tcode{(is_trivially_move_constructible_v && is_trivially_move_assignable_v && is_trivially_destructible_v && is_trivially_move_constructible_v && is_trivially_move_assignable_v && is_trivially_destructible_v)} is \tcode{false}. +\item \tcode{(is_trivially_move_constructible_v \&\& is_trivially_move_assignable_v \&\& is_trivially_destructible_v \&\& is_trivially_move_constructible_v \&\& is_trivially_move_assignable_v \&\& is_trivially_destructible_v)} is \tcode{false}. \end{itemize} \pnum \effects -If \tcode{this->has_value() && rhs.has_value()}, equivalent to \tcode{val = std::move(*rhs)}. Otherwise, if \tcode{this->has_value()}, equivalent to \tcode{reinit-expected(unex, val, std::move(rhs.error()))}. Otherwise, if \tcode{rhs.has_value()}, equivalent to \tcode{reinit-expected(val, unex, std::move(*rhs))}. Otherwise, equivalent to \tcode{unex = std::move(rhs.unex)}. Then, if no exception was thrown, equivalent to: \tcode{has_val = rhs.has_value(); return *this;} When \tcode{E} is an lvalue reference type, each of the cases above that initializes or assigns \tcode{unex} rebinds it: \tcode{unex} comes to refer to the same object as \tcode{rhs}'s error. No previously or subsequently referenced object is assigned through. +If \tcode{this->has_value() \&\& rhs.has_value()}, equivalent to \tcode{\exposid{val} = std::move(*rhs)}. Otherwise, if \tcode{this->has_value()}, equivalent to \tcode{reinit-expected(\exposid{unex}, \exposid{val}, std::move(rhs.error()))}. Otherwise, if \tcode{rhs.has_value()}, equivalent to \tcode{reinit-expected(\exposid{val}, \exposid{unex}, std::move(*rhs))}. Otherwise, equivalent to \tcode{\exposid{unex} = std::move(rhs.\exposid{unex})}. Then, if no exception was thrown, equivalent to: \tcode{has_val = rhs.has_value(); return *this;} When \tcode{E} is an lvalue reference type, each of the cases above that initializes or assigns \exposid{unex} rebinds it: \exposid{unex} comes to refer to the same object as \tcode{rhs}'s error. No previously or subsequently referenced object is assigned through. \pnum \returns @@ -1003,22 +767,23 @@ \pnum \remarks -The exception specification is equivalent to \tcode{is_nothrow_move_assignable_v && is_nothrow_move_constructible_v && is_nothrow_move_assignable_v && is_nothrow_move_constructible_v}. This operator is trivial if \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, \tcode{is_trivially_destructible_v}, \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, and \tcode{is_trivially_destructible_v} are all \tcode{true}. +The exception specification is equivalent to \tcode{is_nothrow_move_assignable_v \&\& is_nothrow_move_constructible_v \&\& is_nothrow_move_assignable_v \&\& is_nothrow_move_constructible_v}. This operator is trivial if \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, \tcode{is_trivially_destructible_v}, \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, and \tcode{is_trivially_destructible_v} are all \tcode{true}. \end{itemdescr} \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template> constexpr expected& operator=(U&& v); +template> + constexpr expected& operator=(U&& v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_same_v>} is \tcode{false}; and \tcode{remove_cvref_t} is not a specialization of \tcode{unexpected}; and \tcode{is_constructible_v} is \tcode{true}; and \tcode{is_assignable_v} is \tcode{true}; and \tcode{is_nothrow_constructible_v || is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}. +\tcode{is_same_v>} is \tcode{false}; and \tcode{remove_cvref_t} is not a specialization of \tcode{unexpected}; and \tcode{is_constructible_v} is \tcode{true}; and \tcode{is_assignable_v} is \tcode{true}; and \tcode{is_nothrow_constructible_v || is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}. \pnum \effects -If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{val = std::forward(v);} Otherwise, equivalent to: \tcode{reinit-expected(val, unex, std::forward(v)); has_val = true;} +If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{\exposid{val} = std::forward(v);} Otherwise, equivalent to: \tcode{reinit-expected(\exposid{val}, \exposid{unex}, std::forward(v)); has_val = true;} \pnum \returns @@ -1027,18 +792,20 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_assignable_v} is \tcode{true}; and \tcode{is_nothrow_constructible_v || is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}; and \tcode{is_assignable_v} is \tcode{true}; and \tcode{is_nothrow_constructible_v || is_nothrow_move_constructible_v || is_nothrow_move_constructible_v} is \tcode{true}. \pnum \effects -If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{reinit-expected(unex, val, e.error()); has_val = false;} Otherwise, equivalent to: \tcode{unex = unexpected(e.error());} +If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{reinit-expected(\exposid{unex}, \exposid{val}, e.error()); has_val = false;} Otherwise, equivalent to: \tcode{\exposid{unex} = unexpected(e.error());} \pnum \returns @@ -1047,8 +814,10 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} @@ -1058,7 +827,7 @@ \pnum \effects -Rebinds \tcode{unex} to refer to the same object as \tcode{e.error()}, destroying \tcode{val} first if \tcode{has_value()} is \tcode{true}. +Rebinds \exposid{unex} to refer to the same object as \tcode{e.error()}, destroying \exposid{val} first if \tcode{has_value()} is \tcode{true}. \pnum \ensures @@ -1075,7 +844,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -1085,12 +855,13 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \tcode{unex} to \tcode{unexpected}'s temporary storage. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \exposid{unex} to \tcode{unexpected}'s temporary storage. \end{itemdescr} \indexlibrarymember{emplace}{expected}% \begin{itemdecl} -template constexpr T& emplace(Args&&... args) noexcept; +template + constexpr T& emplace(Args&&... args) noexcept; \end{itemdecl} \begin{itemdescr} @@ -1100,34 +871,32 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) { destroy_at(addressof(val)); } else { destroy_at(addressof(unex)); has_val = true; } return *construct_at(addressof(val), std::forward(args)...);} +Equivalent to: \tcode{if (has_value()) \{ destroy_at(addressof(\exposid{val})); \} else \{ destroy_at(addressof(\exposid{unex})); has_val = true; \} return *construct_at(addressof(\exposid{val}), std::forward(args)...);} \end{itemdescr} \indexlibrarymember{emplace}{expected}% \begin{itemdecl} template -constexpr T& emplace(initializer_list il, Args&&... args) noexcept; + constexpr T& emplace(initializer_list il, Args&&... args) noexcept; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_nothrow_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_nothrow_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Equivalent to: \tcode{if (has_value()) { destroy_at(addressof(val)); } else { destroy_at(addressof(unex)); has_val = true; } return *construct_at(addressof(val), il, std::forward(args)...);} +Equivalent to: \tcode{if (has_value()) \{ destroy_at(addressof(\exposid{val})); \} else \{ destroy_at(addressof(\exposid{unex})); has_val = true; \} return *construct_at(addressof(\exposid{val}), il, std::forward(args)...);} \end{itemdescr} \rSec3[expected.object.swap]{Swap} \indexlibrarymember{swap}{expected}% \begin{itemdecl} -constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && - is_nothrow_swappable_v && +constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && is_nothrow_swappable_v && is_nothrow_move_constructible_v && - (is_reference_v || - is_nothrow_swappable_v)); + (is_reference_v || is_nothrow_swappable_v)); \end{itemdecl} \begin{itemdescr} @@ -1143,7 +912,7 @@ \pnum \effects -If \tcode{this->has_value()} and \tcode{rhs.has_value()}, equivalent to \tcode{using std::swap; swap(val, rhs.val);}. If neither \tcode{*this} nor \tcode{rhs} contains a value, equivalent to \tcode{using std::swap; swap(unex, rhs.unex);}. If \tcode{rhs.has_value()} is \tcode{false} and \tcode{this->has_value()} is \tcode{true}, exchanges the value and error between \tcode{*this} and \tcode{rhs} (moving through a temporary so a failed move leaves both objects unchanged), leaving \tcode{has_value()} \tcode{false} and \tcode{rhs.has_value()} \tcode{true}. If \tcode{rhs.has_value()} is \tcode{true} and \tcode{this->has_value()} is \tcode{false}, equivalent to \tcode{rhs.swap(*this)}. +If \tcode{this->has_value()} and \tcode{rhs.has_value()}, equivalent to \tcode{using std::swap; swap(\exposid{val}, rhs.\exposid{val});}. If neither \tcode{*this} nor \tcode{rhs} contains a value, equivalent to \tcode{using std::swap; swap(\exposid{unex}, rhs.\exposid{unex});}. If \tcode{rhs.has_value()} is \tcode{false} and \tcode{this->has_value()} is \tcode{true}, exchanges the value and error between \tcode{*this} and \tcode{rhs} (moving through a temporary so a failed move leaves both objects unchanged), leaving \tcode{has_value()} \tcode{false} and \tcode{rhs.has_value()} \tcode{true}. If \tcode{rhs.has_value()} is \tcode{true} and \tcode{this->has_value()} is \tcode{false}, equivalent to \tcode{rhs.swap(*this)}. \pnum \throws @@ -1151,7 +920,7 @@ \pnum \remarks -The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v && is_nothrow_swappable_v && is_nothrow_move_constructible_v && (is_reference_v || is_nothrow_swappable_v)}. +The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v \&\& is_nothrow_swappable_v \&\& is_nothrow_move_constructible_v \&\& (is_reference_v || is_nothrow_swappable_v)}. \end{itemdescr} \indexlibraryglobal{swap}% @@ -1190,7 +959,7 @@ \pnum \returns -\tcode{addressof(val)}. +\tcode{addressof(\exposid{val})}. \end{itemdescr} \indexlibrarymember{operator*}{expected}% @@ -1206,7 +975,7 @@ \pnum \returns -\tcode{val}. +\exposid{val}. \end{itemdescr} \indexlibrarymember{operator*}{expected}% @@ -1222,7 +991,7 @@ \pnum \returns -\tcode{std::move(val)}. +\tcode{std::move(\exposid{val})}. \end{itemdescr} \indexlibrarymember{operator bool}{expected}% @@ -1251,7 +1020,7 @@ \pnum \returns -\tcode{val}, if \tcode{has_value()} is \tcode{true}. +\exposid{val}, if \tcode{has_value()} is \tcode{true}. \pnum \throws @@ -1271,7 +1040,7 @@ \pnum \returns -\tcode{std::move(val)}, if \tcode{has_value()} is \tcode{true}. +\tcode{std::move(\exposid{val})}, if \tcode{has_value()} is \tcode{true}. \pnum \throws @@ -1291,7 +1060,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -1307,12 +1076,13 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{value_or}{expected}% \begin{itemdecl} -template> constexpr T value_or(U&& def) const&; +template> + constexpr T value_or(U&& def) const&; \end{itemdecl} \begin{itemdescr} @@ -1327,7 +1097,8 @@ \indexlibrarymember{value_or}{expected}% \begin{itemdecl} -template> constexpr T value_or(U&& def) &&; +template> + constexpr T value_or(U&& def) &&; \end{itemdecl} \begin{itemdescr} @@ -1343,17 +1114,17 @@ \indexlibrarymember{error_or}{expected}% \begin{itemdecl} template -constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_copy_constructible_v::error_value_type>} is \tcode{true} and \tcode{is_convertible_v::error_value_type>} is \tcode{true}. +\tcode{is_copy_constructible_v::\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v::\exposid{error-value-type}>} is \tcode{true}. \pnum \mandates -\tcode{is_copy_constructible_v} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_copy_constructible_v<\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. \pnum \returns @@ -1362,17 +1133,18 @@ \indexlibrarymember{error_or}{expected}% \begin{itemdecl} -template constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; +template + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_move_constructible_v::error_value_type>} is \tcode{true} and \tcode{is_convertible_v::error_value_type>} is \tcode{true}. +\tcode{is_move_constructible_v::\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v::\exposid{error-value-type}>} is \tcode{true}. \pnum \mandates -\tcode{is_move_constructible_v} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_move_constructible_v<\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. \pnum \returns @@ -1383,8 +1155,10 @@ \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &; -template constexpr auto and_then(F&& f) const&; +template + constexpr auto and_then(F&& f) &; +template + constexpr auto and_then(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -1394,17 +1168,19 @@ \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), val); else return U(unexpect, error());} where \tcode{U} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), \exposid{val}); else return U(unexpect, error());} where \tcode{U} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &&; -template constexpr auto and_then(F&& f) const&&; +template + constexpr auto and_then(F&& f) &&; +template + constexpr auto and_then(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -1414,23 +1190,25 @@ \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), std::move(val)); else return U(unexpect, std::move(error()));} where \tcode{U} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), std::move(\exposid{val})); else return U(unexpect, std::move(error()));} where \tcode{U} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &; -template constexpr auto or_else(F&& f) const&; +template + constexpr auto or_else(F&& f) &; +template + constexpr auto or_else(F&& f) const&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1438,19 +1216,21 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(in_place, val); else return invoke(std::forward(f), error());} where \tcode{G} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return G(in_place, \exposid{val}); else return invoke(std::forward(f), error());} where \tcode{G} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &&; -template constexpr auto or_else(F&& f) const&&; +template + constexpr auto or_else(F&& f) &&; +template + constexpr auto or_else(F&& f) const&&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1458,13 +1238,15 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(in_place, std::move(val)); else return invoke(std::forward(f), std::move(error()));} where \tcode{G} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return G(in_place, std::move(\exposid{val})); else return invoke(std::forward(f), std::move(error()));} where \tcode{G} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &; -template constexpr auto transform(F&& f) const&; +template + constexpr auto transform(F&& f) &; +template + constexpr auto transform(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -1474,13 +1256,15 @@ \pnum \effects -Equivalent to: \tcode{if (!has_value()) return U(unexpect, error()); else return expected(in_place, invoke(std::forward(f), val));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. +Equivalent to: \tcode{if (!has_value()) return U(unexpect, error()); else return expected(in_place, invoke(std::forward(f), \exposid{val}));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &&; -template constexpr auto transform(F&& f) const&&; +template + constexpr auto transform(F&& f) &&; +template + constexpr auto transform(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -1490,19 +1274,21 @@ \pnum \effects -Equivalent to: \tcode{if (!has_value()) return U(unexpect, std::move(error())); else return expected(in_place, invoke(std::forward(f), std::move(val)));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. +Equivalent to: \tcode{if (!has_value()) return U(unexpect, std::move(error())); else return expected(in_place, invoke(std::forward(f), std::move(\exposid{val})));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &; -template constexpr auto transform_error(F&& f) const&; +template + constexpr auto transform_error(F&& f) &; +template + constexpr auto transform_error(F&& f) const&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1515,19 +1301,21 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(in_place, val); else return expected(unexpect, invoke(std::forward(f), error()));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. +Equivalent to: \tcode{if (has_value()) return G(in_place, \exposid{val}); else return expected(unexpect, invoke(std::forward(f), error()));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &&; -template constexpr auto transform_error(F&& f) const&&; +template + constexpr auto transform_error(F&& f) &&; +template + constexpr auto transform_error(F&& f) const&&; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1540,7 +1328,7 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(in_place, std::move(val)); else return expected(unexpect, invoke(std::forward(f), std::move(error())));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. +Equivalent to: \tcode{if (has_value()) return G(in_place, std::move(\exposid{val})); else return expected(unexpect, invoke(std::forward(f), std::move(error())));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. \end{itemdescr} \rSec3[expected.object.eq]{Equality operators} @@ -1548,7 +1336,7 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const expected& y); + friend constexpr bool operator==(const expected& x, const expected& y); \end{itemdecl} \begin{itemdescr} @@ -1567,7 +1355,8 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} -template friend constexpr bool operator==(const expected& x, const T2& val); +template + friend constexpr bool operator==(const expected& x, const T2& val); \end{itemdecl} \begin{itemdescr} @@ -1581,13 +1370,13 @@ \pnum \returns -\tcode{x.has_value() && static_cast(*x == val)}. +\tcode{x.has_value() \&\& static_cast(*x == val)}. \end{itemdescr} \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const unexpected& e); + friend constexpr bool operator==(const expected& x, const unexpected& e); \end{itemdecl} \begin{itemdescr} @@ -1597,5 +1386,5 @@ \pnum \returns -\tcode{!x.has_value() && static_cast(x.error() == e.error())}. +\tcode{!x.has_value() \&\& static_cast(x.error() == e.error())}. \end{itemdescr} diff --git a/papers/wording/fragments/expected.ref.tex b/papers/wording/fragments/expected.ref.tex index 76ac474..0b6768d 100644 --- a/papers/wording/fragments/expected.ref.tex +++ b/papers/wording/fragments/expected.ref.tex @@ -16,253 +16,113 @@ template using rebind = expected; - // ------------------------------------------------------------------------- - // Constructors - // ------------------------------------------------------------------------- + expected() = delete; - expected() = BEMAN_EXPECTED_DELETE_MSG( - "expected: no default constructor; T& cannot be null"); - - // Copy constructor (trivial path). Unconstrained; see the primary - // template's copy constructor for why. constexpr expected(const expected&) = default; - // Copy constructor (non-trivial path) - constexpr expected(const expected& rhs) noexcept(is_nothrow_copy_constructible_v) - requires(is_copy_constructible_v && !is_trivially_copy_constructible_v); + constexpr expected(const expected& rhs) noexcept( + is_nothrow_copy_constructible_v); - // Move constructor (trivial path). Unconstrained; no explicit noexcept. constexpr expected(expected&&) = default; - // Move constructor (non-trivial path) - constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v) - requires(is_move_constructible_v && !is_trivially_move_constructible_v); + constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v); - // Deleted: no in-place value constructor — T& cannot be constructed in-place - template - constexpr expected(in_place_t, Args&&...) = BEMAN_EXPECTED_DELETE_MSG( - "expected: no in-place value constructor; T& cannot be constructed " - "in-place — pass a U convertible to T&"); + template constexpr expected(in_place_t, Args&&...) = delete; - // Value constructor — takes U that can bind to T& template - requires(!is_same_v, in_place_t> && - !is_same_v, expected> && - !@\exposidnc{is-unexpected-specialization}@>::value && - is_constructible_v && !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(U&& u) noexcept(is_nothrow_constructible_v); - // Deleted: binding a temporary to T& creates a dangling reference - template - requires(reference_constructs_from_temporary_v) - constexpr expected(U&&) = - BEMAN_EXPECTED_DELETE_MSG("expected: argument would bind a temporary that " - "dangles; pass an lvalue reference"); + template constexpr expected(U&&) = delete; - // Converting constructor from expected (copy) — value-E path template - requires(!is_reference_v && is_constructible_v && - is_constructible_v && - !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); - // Converting constructor from expected (move) — value-E path template - requires(!is_reference_v && is_constructible_v && - is_constructible_v && !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); - // Converting constructor from expected (copy/move) — reference-E path: only - // accepts sources whose error type G is itself a reference convertible to E. template - requires(is_reference_v && is_reference_v && is_constructible_v && - is_convertible_v && !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); template - requires(is_reference_v && is_reference_v && is_constructible_v && - is_convertible_v && !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); - // Constructor from unexpected const& / && — value-E path template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(const unexpected& e); template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e); - // Constructor from unexpected — reference-E path. Allowed only when G is itself a - // reference, i.e. the source unexpected holds a reference to an external object, so - // binding E& to e.error() cannot dangle regardless of the source's value category. No - // const_cast is needed. template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) + expected(const unexpected& e) noexcept; template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; - // Deleted for reference E with value G: the referent lives inside the unexpected - // object, so binding E& to it would dangle once a temporary source is destroyed. Use - // (unexpect, lvalue), or an unexpected holding an external object, instead. - template - requires(is_reference_v && !is_reference_v) - constexpr expected(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would " - "dangle — use unexpected"); + template constexpr expected(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected(unexpected&&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would " - "dangle — use unexpected"); + constexpr expected(unexpected&&) = delete; - // In-place constructor for error - template - requires(is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr explicit expected(unexpect_t, Args&&... args); + template constexpr explicit expected(unexpect_t, Args&&... args); - // Deleted: single argument would bind E& to a temporary — dangling prevention - template - requires(@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " - "temporary that dangles; pass an lvalue reference"); + template constexpr expected(unexpect_t, Args&&...) = delete; - // Deleted catch-all: reference E, argument neither constructible nor a dangling case template requires(is_reference_v && !is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = BEMAN_EXPECTED_DELETE_MSG( - "expected: no viable conversion from the given argument(s) to E&"); + constexpr expected(unexpect_t, Args&&...) = delete; - // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); template - requires is_reference_v - constexpr expected(unexpect_t, initializer_list, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG("expected: initializer-list error construction " - "cannot bind a reference; pass an lvalue reference"); + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; - // ------------------------------------------------------------------------- - // Destructor - // ------------------------------------------------------------------------- + constexpr ~expected() = default; - constexpr ~expected() - requires is_trivially_destructible_v - = default; + constexpr ~expected(); - constexpr ~expected() - requires(!is_trivially_destructible_v); + constexpr expected& operator=(const expected&) = default; - // ------------------------------------------------------------------------- - // Assignment (rebind semantics) - // ------------------------------------------------------------------------- + constexpr expected& operator=(const expected& rhs) noexcept( + is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); - // Copy assignment (trivial path) - constexpr expected& operator=(const expected&) - requires(is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v) - = default; + constexpr expected& operator=(expected&&) noexcept = default; - // Copy assignment (non-trivial path) - constexpr expected& operator=(const expected& rhs) noexcept( - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v) - requires((is_reference_v || - (is_copy_constructible_v && is_copy_assignable_v)) && - !(is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v)); - - // Move assignment (trivial path) - constexpr expected& operator=(expected&&) noexcept - requires(is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v) - = default; - - // Move assignment (non-trivial path) constexpr expected& operator=(expected&& rhs) noexcept( - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v) - requires((is_reference_v || - (is_move_constructible_v && is_move_assignable_v)) && - !(is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v)); + is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); - // Rebind reference from lvalue - template - requires(!is_same_v, expected> && - !@\exposidnc{is-unexpected-specialization}@>::value && - is_constructible_v && !reference_constructs_from_temporary_v) - constexpr expected& operator=(U&& u); + template constexpr expected& operator=(U&& u); - // Assignment from unexpected — value-E path - template - requires(!is_reference_v && is_constructible_v && - is_assignable_v) - constexpr expected& operator=(const unexpected& e); + template constexpr expected& operator=(const unexpected& e); - template - requires(!is_reference_v && is_constructible_v && is_assignable_v) - constexpr expected& operator=(unexpected&& e); + template constexpr expected& operator=(unexpected&& e); - // Rebinding assignment for reference E from reference G — binds unex_ to the external - // referent. - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(const unexpected& e); + template constexpr expected& operator=(const unexpected& e); - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(unexpected&& e); + template constexpr expected& operator=(unexpected&& e); - // Deleted for reference E with value G: would rebind E& to unexpected's temporary - // storage. - template - requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot assign from unexpected; the value would dangle — " - "use unexpected"); + template constexpr expected& operator=(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(unexpected&&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot assign from unexpected; the value would dangle — " - "use unexpected"); + constexpr expected& operator=(unexpected&&) = delete; - // emplace — rebind the reference template - requires(is_constructible_v && !reference_constructs_from_temporary_v) constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v); - // ------------------------------------------------------------------------- - // Swap - // ------------------------------------------------------------------------- - constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && (is_reference_v || - is_nothrow_swappable_v)) - requires((is_reference_v || is_swappable_v) && is_move_constructible_v); - - friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))) - requires((is_reference_v || is_swappable_v) && is_move_constructible_v); + is_nothrow_swappable_v)); - // ------------------------------------------------------------------------- - // Observers - // ------------------------------------------------------------------------- + friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))); constexpr T* operator->() const noexcept; constexpr T& operator*() const noexcept; @@ -273,82 +133,43 @@ constexpr T& value() const&; constexpr T& value() &&; - // error() — shallow const: always returns E& regardless of const on expected constexpr const E& error() const& noexcept; constexpr E& error() & noexcept; constexpr const E&& error() const&& noexcept; constexpr E&& error() && noexcept; - template> - requires(is_object_v && !is_array_v) - constexpr remove_cv_t value_or(U&& def) const; + template> constexpr remove_cv_t value_or(U&& def) const; - // Constraints spell error_value_type as its underlying trait expression rather than - // the member typedef: clang (through 22) fails to match an out-of-line constrained - // member of a partial specialization when the requires-clause names a member typedef - // of the class. template - requires(is_copy_constructible_v>> && - is_convertible_v>>) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; template - requires(is_move_constructible_v>> && - is_convertible_v>>) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; - // ------------------------------------------------------------------------- - // Monadic operations - // ------------------------------------------------------------------------- - - template - requires is_constructible_v - constexpr auto and_then(F&& f) &; - template - requires is_constructible_v - constexpr auto and_then(F&& f) &&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&&; + template 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&&; - // transform: f receives T& (value); error propagates as E; result is expected - template - requires is_constructible_v - constexpr auto transform(F&& f) &; - template - requires is_constructible_v - constexpr auto transform(F&& f) &&; - template - requires is_constructible_v - constexpr auto transform(F&& f) const&; - template - requires is_constructible_v - constexpr auto transform(F&& f) const&&; - - // transform_error: f receives E; value propagates as T&; result is expected + 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&&; - // ------------------------------------------------------------------------- - // Equality operators (hidden friends) - // ------------------------------------------------------------------------- - template - requires(!is_void_v) friend constexpr bool operator==(const expected& x, const expected& y); template - requires(!@\exposidnc{is-expected-specialization}@::value) friend constexpr bool operator==(const expected& x, const T2& val); template @@ -364,27 +185,25 @@ } \end{codeblock} -\begin{itemdescr} \pnum \mandates -A program that instantiates the definition of \tcode{expected} with an \tcode{E} that is not a valid template argument for \tcode{unexpected} is ill-formed. \tcode{T} shall be an object type that is not an array type, \tcode{in_place_t}, \tcode{unexpect_t}, or a specialization of \tcode{unexpected}. +A program that instantiates the definition of \tcode{expected} with an \tcode{E} that is not a valid template argument for \tcode{unexpected} is ill-formed. \tcode{T} shall be an object type that is not an array type, \tcode{in_place_t}, \tcode{unexpect_t}, or a specialization of \tcode{unexpected}. \pnum \remarks -An object of type \tcode{expected} either represents a reference to an object of type \tcode{T}, or holds an error. Member \tcode{has_val} indicates whether the object represents a reference. When it represents a reference, member \tcode{val} points to the referenced object, which is not owned by the \tcode{expected} object. Otherwise, the error is \tcode{unex.error()}. -\end{itemdescr} +An object of type \tcode{expected} either represents a reference to an object of type \tcode{T}, or holds an error. Member \tcode{has_val} indicates whether the object represents a reference. When it represents a reference, member \exposid{val} points to the referenced object, which is not owned by the \tcode{expected} object. Otherwise, the error is \tcode{\exposid{unex}.error()}. \rSec3[expected.ref.cons]{Constructors} \indexlibraryctor{expected}% \begin{itemdecl} -; +expected() = delete; \end{itemdecl} \begin{itemdescr} \pnum \remarks -\tcode{expected} has no default constructor: a reference cannot be null, so there is no empty state to default-construct into. +\tcode{expected} has no default constructor: a reference cannot be null, so there is no empty state to default-construct into. \end{itemdescr} \indexlibraryctor{expected}% @@ -395,7 +214,7 @@ \begin{itemdescr} \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, initializes \tcode{val} with \tcode{rhs.val}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \tcode{unex} with \tcode{rhs.unex}. +If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with \tcode{rhs.\exposid{val}}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \exposid{unex} with \tcode{rhs.\exposid{unex}}. \pnum \ensures @@ -419,7 +238,7 @@ \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, initializes \tcode{val} with \tcode{rhs.val}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \tcode{unex} with \tcode{rhs.unex}. +If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with \tcode{rhs.\exposid{val}}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \exposid{unex} with \tcode{rhs.\exposid{unex}}. \pnum \ensures @@ -438,7 +257,7 @@ \begin{itemdescr} \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, initializes \tcode{val} with \tcode{rhs.val}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \tcode{unex} with \tcode{std::move(rhs.unex)}. +If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with \tcode{rhs.\exposid{val}}, so that \tcode{*this} and \tcode{rhs} refer to the same object; otherwise, initializes \exposid{unex} with \tcode{std::move(rhs.\exposid{unex})}. \pnum \ensures @@ -451,30 +270,30 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(in_place_t, Args&&...); +template + constexpr expected(in_place_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} \pnum \remarks -\tcode{expected} has no in-place value constructor: \tcode{T&} cannot be constructed in-place. Pass a \tcode{U} convertible to \tcode{T&} instead. +\tcode{expected} has no in-place value constructor: \tcode{T\&} cannot be constructed in-place. Pass a \tcode{U} convertible to \tcode{T\&} instead. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) - expected(U&& u) noexcept(is_nothrow_constructible_v); + constexpr explicit(!is_convertible_v) expected(U&& u) noexcept(is_nothrow_constructible_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{remove_cvref_t} is not \tcode{in_place_t}, \tcode{expected}, or a specialization of \tcode{unexpected}; \tcode{is_constructible_v} is \tcode{true}; and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\tcode{remove_cvref_t} is not \tcode{in_place_t}, \tcode{expected}, or a specialization of \tcode{unexpected}; \tcode{is_constructible_v} is \tcode{true}; and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \pnum \effects -Let \tcode{r} be the lvalue result of \tcode{T& r = std::forward(u);}. Initializes \tcode{val} with \tcode{addressof(r)}. +Let \tcode{r} be the lvalue result of \tcode{T\& r = std::forward(u);}. Initializes \exposid{val} with \tcode{addressof(r)}. \pnum \ensures @@ -483,57 +302,54 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(U&&); +template + constexpr expected(U&&) = delete; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{reference_constructs_from_temporary_v} is \tcode{true}. +\tcode{reference_constructs_from_temporary_v} is \tcode{true}. \pnum \remarks -A constructor for which \tcode{reference_constructs_from_temporary_v} is \tcode{true} — one that would bind \tcode{T&} to a temporary — is defined as deleted. +A constructor for which \tcode{reference_constructs_from_temporary_v} is \tcode{true} — one that would bind \tcode{T\&} to a temporary — is defined as deleted. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(const expected& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(expected&& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}; \tcode{reference_constructs_from_temporary_v} is \tcode{false}; and \tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}; \tcode{reference_constructs_from_temporary_v} is \tcode{false}; and \tcode{is_constructible_v} is \tcode{true}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, initializes \tcode{val} with \tcode{addressof(*rhs)}, so that \tcode{*this} refers to the object referred to by \tcode{rhs}; otherwise, initializes \tcode{unex} with the error of \tcode{rhs}. No object referred to by \tcode{rhs} is moved from. +If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with \tcode{addressof(*rhs)}, so that \tcode{*this} refers to the object referred to by \tcode{rhs}; otherwise, initializes \exposid{unex} with the error of \tcode{rhs}. No object referred to by \tcode{rhs} is moved from. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(const expected& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(const expected& rhs); template -constexpr explicit(!is_convertible_v || !is_convertible_v) - expected(expected&& rhs); + constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}; \tcode{reference_constructs_from_temporary_v} is \tcode{false}; \tcode{G} is a reference type; and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}; \tcode{reference_constructs_from_temporary_v} is \tcode{false}; \tcode{G} is a reference type; and \tcode{is_convertible_v} is \tcode{true}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}, initializes \tcode{val} with \tcode{addressof(*rhs)}, so that \tcode{*this} refers to the object referred to by \tcode{rhs}; otherwise, initializes \tcode{unex} with the error of \tcode{rhs}. No object referred to by \tcode{rhs} is moved from. +If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with \tcode{addressof(*rhs)}, so that \tcode{*this} refers to the object referred to by \tcode{rhs}; otherwise, initializes \exposid{unex} with the error of \tcode{rhs}. No object referred to by \tcode{rhs} is moved from. \pnum \remarks @@ -543,19 +359,19 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e); + constexpr explicit(!is_convertible_v) expected(const unexpected& e); template -constexpr explicit(!is_convertible_v) expected(unexpected&& e); + constexpr explicit(!is_convertible_v) expected(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \effects -Initializes \tcode{unex} with the error of \tcode{e}. +Initializes \exposid{unex} with the error of \tcode{e}. \pnum \ensures @@ -565,9 +381,9 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; template -constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; + constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; \end{itemdecl} \begin{itemdescr} @@ -577,7 +393,7 @@ \pnum \effects -Initializes \tcode{unex} with the error of \tcode{e}. +Initializes \exposid{unex} with the error of \tcode{e}. \pnum \ensures @@ -590,7 +406,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -600,12 +417,13 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E\&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr explicit expected(unexpect_t, Args&&... args); +template + constexpr explicit expected(unexpect_t, Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -615,7 +433,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{in_place} and \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{in_place} and \tcode{std::forward(args)...}. \pnum \ensures @@ -624,7 +442,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -634,23 +453,23 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. +When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E\&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); + constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{in_place}, \tcode{il}, and \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{in_place}, \tcode{il}, and \tcode{std::forward(args)...}. \pnum \ensures @@ -664,7 +483,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -710,7 +529,7 @@ \pnum \effects -If \tcode{has_value()} is \tcode{false}, destroys \tcode{unex}. \tcode{T} is not destroyed; \tcode{*this} never owns the object it refers to. +If \tcode{has_value()} is \tcode{false}, destroys \exposid{unex}. \tcode{T} is not destroyed; \tcode{*this} never owns the object it refers to. \pnum \remarks @@ -731,7 +550,7 @@ \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.val} to \tcode{val}; otherwise destroys \tcode{unex} and initializes \tcode{val} with \tcode{rhs.val}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \tcode{unex}, as for the primary template. In every case \tcode{*this} comes to refer to the object \tcode{rhs} refers to, or to hold the error of \tcode{rhs}. +If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.\exposid{val}} to \exposid{val}; otherwise destroys \exposid{unex} and initializes \exposid{val} with \tcode{rhs.\exposid{val}}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \exposid{unex}, as for the primary template. In every case \tcode{*this} comes to refer to the object \tcode{rhs} refers to, or to hold the error of \tcode{rhs}. \pnum \returns @@ -739,25 +558,25 @@ \pnum \remarks -Assignment rebinds: assigning to an \tcode{expected} that holds a value changes which object it refers to. It never assigns through to the referent. This operator is trivial. +Assignment rebinds: assigning to an \tcode{expected} that holds a value changes which object it refers to. It never assigns through to the referent. This operator is trivial. \end{itemdescr} \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -constexpr expected& operator=(const expected& rhs) noexcept( - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); -constexpr expected& operator=(expected&& rhs) noexcept( - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); +constexpr expected& operator=(const expected& rhs) noexcept(is_nothrow_copy_constructible_v && + is_nothrow_copy_assignable_v); +constexpr expected& operator=(expected&& rhs) noexcept(is_nothrow_move_constructible_v && + is_nothrow_move_assignable_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v || (is_copy_constructible_v && is_copy_assignable_v)} is \tcode{true} and \tcode{(is_trivially_copy_constructible_v && is_trivially_copy_assignable_v && is_trivially_destructible_v)} is \tcode{false}. +\tcode{is_reference_v || (is_copy_constructible_v \&\& is_copy_assignable_v)} is \tcode{true} and \tcode{(is_trivially_copy_constructible_v \&\& is_trivially_copy_assignable_v \&\& is_trivially_destructible_v)} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.val} to \tcode{val}; otherwise destroys \tcode{unex} and initializes \tcode{val} with \tcode{rhs.val}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \tcode{unex}, as for the primary template. In every case \tcode{*this} comes to refer to the object \tcode{rhs} refers to, or to hold the error of \tcode{rhs}. +If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.\exposid{val}} to \exposid{val}; otherwise destroys \exposid{unex} and initializes \exposid{val} with \tcode{rhs.\exposid{val}}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \exposid{unex}, as for the primary template. In every case \tcode{*this} comes to refer to the object \tcode{rhs} refers to, or to hold the error of \tcode{rhs}. \pnum \returns @@ -780,7 +599,7 @@ \pnum \effects -If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.val} to \tcode{val}; otherwise destroys \tcode{unex} and initializes \tcode{val} with \tcode{rhs.val}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \tcode{unex}, as for the primary template. +If \tcode{rhs.has_value()} is \tcode{true}: if \tcode{has_value()} is \tcode{true}, assigns \tcode{rhs.\exposid{val}} to \exposid{val}; otherwise destroys \exposid{unex} and initializes \exposid{val} with \tcode{rhs.\exposid{val}}. If \tcode{rhs.has_value()} is \tcode{false}, the error of \tcode{rhs} is assigned to or used to initialize \exposid{unex}, as for the primary template. \pnum \returns @@ -793,17 +612,18 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(U&& u); +template + constexpr expected& operator=(U&& u); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{remove_cvref_t} is neither \tcode{expected} nor a specialization of \tcode{unexpected}, \tcode{is_constructible_v} is \tcode{true}, and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\tcode{remove_cvref_t} is neither \tcode{expected} nor a specialization of \tcode{unexpected}, \tcode{is_constructible_v} is \tcode{true}, and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \pnum \effects -Let \tcode{r} be the lvalue result of \tcode{T& r = std::forward(u);}. If \tcode{has_value()} is \tcode{true}, assigns \tcode{addressof(r)} to \tcode{val}. Otherwise, destroys \tcode{unex}, initializes \tcode{val} with \tcode{addressof(r)}, and sets \tcode{has_val} to \tcode{true}; if binding \tcode{r} throws, \tcode{*this} is left unchanged. +Let \tcode{r} be the lvalue result of \tcode{T\& r = std::forward(u);}. If \tcode{has_value()} is \tcode{true}, assigns \tcode{addressof(r)} to \exposid{val}. Otherwise, destroys \exposid{unex}, initializes \exposid{val} with \tcode{addressof(r)}, and sets \tcode{has_val} to \tcode{true}; if binding \tcode{r} throws, \tcode{*this} is left unchanged. \pnum \returns @@ -812,18 +632,20 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true} and \tcode{is_assignable_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true} and \tcode{is_assignable_v} is \tcode{true}. \pnum \effects -Makes \tcode{*this} hold the error of \tcode{e}, reinitializing \tcode{unex} from \tcode{e} rather than assigning through it. +Makes \tcode{*this} hold the error of \tcode{e}, reinitializing \exposid{unex} from \tcode{e} rather than assigning through it. \pnum \returns @@ -832,8 +654,10 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} @@ -843,7 +667,7 @@ \pnum \effects -Makes \tcode{*this} hold the error of \tcode{e}, reinitializing \tcode{unex} from \tcode{e} rather than assigning through it. \tcode{unex.error()} thereafter refers to the same object as \tcode{e.error()}; the previously referenced object, if any, is not modified. +Makes \tcode{*this} hold the error of \tcode{e}, reinitializing \exposid{unex} from \tcode{e} rather than assigning through it. \tcode{\exposid{unex}.error()} thereafter refers to the same object as \tcode{e.error()}; the previously referenced object, if any, is not modified. \pnum \returns @@ -856,7 +680,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -866,27 +691,27 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \tcode{unex} to \tcode{unexpected}'s temporary storage. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \exposid{unex} to \tcode{unexpected}'s temporary storage. \end{itemdescr} \indexlibrarymember{emplace}{expected}% \begin{itemdecl} template -constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v); + constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true} and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\tcode{is_constructible_v} is \tcode{true} and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \pnum \effects -Rebinds \tcode{*this} to refer to the object bound by \tcode{T& r = std::forward(u);}: if \tcode{has_value()} is \tcode{false}, destroys \tcode{unex} first. Sets \tcode{val} to \tcode{addressof(r)} and \tcode{has_val} to \tcode{true}. +Rebinds \tcode{*this} to refer to the object bound by \tcode{T\& r = std::forward(u);}: if \tcode{has_value()} is \tcode{false}, destroys \exposid{unex} first. Sets \exposid{val} to \tcode{addressof(r)} and \tcode{has_val} to \tcode{true}. \pnum \returns -\tcode{*val}. +\tcode{*\exposid{val}}. \end{itemdescr} \rSec3[expected.ref.swap]{Swap} @@ -894,8 +719,7 @@ \indexlibrarymember{swap}{expected}% \begin{itemdecl} constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && - (is_reference_v || - is_nothrow_swappable_v)); + (is_reference_v || is_nothrow_swappable_v)); \end{itemdecl} \begin{itemdescr} @@ -905,11 +729,11 @@ \pnum \effects -Exchanges the states of \tcode{*this} and \tcode{rhs}. When both hold values, exchanges \tcode{val} and \tcode{rhs.val} — the referenced objects are not swapped. Otherwise behaves as the primary template's \tcode{swap} does for the error. +Exchanges the states of \tcode{*this} and \tcode{rhs}. When both hold values, exchanges \exposid{val} and \tcode{rhs.\exposid{val}} — the referenced objects are not swapped. Otherwise behaves as the primary template's \tcode{swap} does for the error. \pnum \remarks -The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v && (is_reference_v || is_nothrow_swappable_v)}. +The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v \&\& (is_reference_v || is_nothrow_swappable_v)}. \end{itemdescr} \indexlibraryglobal{swap}% @@ -941,11 +765,11 @@ \pnum \returns -\tcode{val}. +\exposid{val}. \pnum \remarks -This is a \tcode{const} member function that returns a non-\tcode{const} \tcode{T*}; the constness of \tcode{*this} does not propagate to the referenced object. For deep \tcode{const}, use \tcode{expected}. +This is a \tcode{const} member function that returns a non-\tcode{const} \tcode{T*}; the constness of \tcode{*this} does not propagate to the referenced object. For deep \tcode{const}, use \tcode{expected}. \end{itemdescr} \indexlibrarymember{operator*}{expected}% @@ -960,11 +784,11 @@ \pnum \returns -\tcode{*val}. +\tcode{*\exposid{val}}. \pnum \remarks -This is a \tcode{const} member function that returns a non-\tcode{const} \tcode{T&}; the constness of \tcode{*this} does not propagate to the referenced object. For deep \tcode{const}, use \tcode{expected}. +This is a \tcode{const} member function that returns a non-\tcode{const} \tcode{T\&}; the constness of \tcode{*this} does not propagate to the referenced object. For deep \tcode{const}, use \tcode{expected}. \end{itemdescr} \indexlibrarymember{operator bool}{expected}% @@ -992,7 +816,7 @@ \pnum \returns -\tcode{*val} if \tcode{has_value()} is \tcode{true}. +\tcode{*\exposid{val}} if \tcode{has_value()} is \tcode{true}. \pnum \throws @@ -1007,7 +831,7 @@ \begin{itemdescr} \pnum \returns -\tcode{*val} if \tcode{has_value()} is \tcode{true}. +\tcode{*\exposid{val}} if \tcode{has_value()} is \tcode{true}. \pnum \throws @@ -1027,7 +851,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -1043,12 +867,13 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{value_or}{expected}% \begin{itemdecl} -template> constexpr remove_cv_t value_or(U&& def) const; +template> + constexpr remove_cv_t value_or(U&& def) const; \end{itemdecl} \begin{itemdescr} @@ -1058,17 +883,17 @@ \pnum \mandates -\tcode{is_convertible_v>} and \tcode{is_convertible_v>} are \tcode{true}. +\tcode{is_convertible_v>} and \tcode{is_convertible_v>} are \tcode{true}. \pnum \returns -\tcode{has_value() ? static_cast>(*val) : static_cast>(std::forward(def))}. The result is an object, never a reference. +\tcode{has_value() ? static_cast>(*\exposid{val}) : static_cast>(std::forward(def))}. The result is an object, never a reference. \end{itemdescr} \indexlibrarymember{error_or}{expected}% \begin{itemdecl} template -constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; \end{itemdecl} \begin{itemdescr} @@ -1083,7 +908,8 @@ \indexlibrarymember{error_or}{expected}% \begin{itemdecl} -template constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; +template + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; \end{itemdecl} \begin{itemdescr} @@ -1100,8 +926,10 @@ \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &; -template constexpr auto and_then(F&& f) const&; +template + constexpr auto and_then(F&& f) &; +template + constexpr auto and_then(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -1111,21 +939,23 @@ \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), *val); else return U(unexpect, error());} where \tcode{U} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), *\exposid{val}); else return U(unexpect, error());} where \tcode{U} is \tcode{remove_cvref_t>}. \pnum \remarks -The member templates \tcode{and_then}, \tcode{or_else}, \tcode{transform}, and \tcode{transform_error} behave as specified for the primary template, with one difference: the value is passed to the callable as \tcode{T&} for every ref-qualification of \tcode{*this}. An rvalue \tcode{expected} does not pass its referent as an rvalue; the object referred to is never moved from by these operations. +The member templates \tcode{and_then}, \tcode{or_else}, \tcode{transform}, and \tcode{transform_error} behave as specified for the primary template, with one difference: the value is passed to the callable as \tcode{T\&} for every ref-qualification of \tcode{*this}. An rvalue \tcode{expected} does not pass its referent as an rvalue; the object referred to is never moved from by these operations. \end{itemdescr} \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &&; -template constexpr auto and_then(F&& f) const&&; +template + constexpr auto and_then(F&& f) &&; +template + constexpr auto and_then(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -1135,49 +965,55 @@ \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{error_type} is the same type as \tcode{E}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), *val); else return U(unexpect, std::move(error()));} where \tcode{U} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return invoke(std::forward(f), *\exposid{val}); else return U(unexpect, std::move(error()));} where \tcode{U} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &; -template constexpr auto or_else(F&& f) const&; +template + constexpr auto or_else(F&& f) &; +template + constexpr auto or_else(F&& f) const&; \end{itemdecl} \begin{itemdescr} \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{value_type} is the same type as \tcode{T&}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{value_type} is the same type as \tcode{T\&}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(*val); else return invoke(std::forward(f), error());} where \tcode{G} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return G(*\exposid{val}); else return invoke(std::forward(f), error());} where \tcode{G} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &&; -template constexpr auto or_else(F&& f) const&&; +template + constexpr auto or_else(F&& f) &&; +template + constexpr auto or_else(F&& f) const&&; \end{itemdecl} \begin{itemdescr} \pnum \mandates -\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{value_type} is the same type as \tcode{T&}. +\tcode{remove_cvref_t>} is a specialization of \tcode{expected} and its \tcode{value_type} is the same type as \tcode{T\&}. \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(*val); else return invoke(std::forward(f), std::move(error()));} where \tcode{G} is \tcode{remove_cvref_t>}. +Equivalent to: \tcode{if (has_value()) return G(*\exposid{val}); else return invoke(std::forward(f), std::move(error()));} where \tcode{G} is \tcode{remove_cvref_t>}. \end{itemdescr} \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &; -template constexpr auto transform(F&& f) const&; +template + constexpr auto transform(F&& f) &; +template + constexpr auto transform(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -1187,13 +1023,15 @@ \pnum \effects -Equivalent to: \tcode{if (!has_value()) return U(unexpect, error()); else return expected(in_place, invoke(std::forward(f), *val));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. +Equivalent to: \tcode{if (!has_value()) return U(unexpect, error()); else return expected(in_place, invoke(std::forward(f), *\exposid{val}));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &&; -template constexpr auto transform(F&& f) const&&; +template + constexpr auto transform(F&& f) &&; +template + constexpr auto transform(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -1203,13 +1041,15 @@ \pnum \effects -Equivalent to: \tcode{if (!has_value()) return U(unexpect, std::move(error())); else return expected(in_place, invoke(std::forward(f), *val));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. +Equivalent to: \tcode{if (!has_value()) return U(unexpect, std::move(error())); else return expected(in_place, invoke(std::forward(f), *\exposid{val}));} where \tcode{U2} is \tcode{remove_cv_t>} and \tcode{U} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &; -template constexpr auto transform_error(F&& f) const&; +template + constexpr auto transform_error(F&& f) &; +template + constexpr auto transform_error(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -1224,13 +1064,15 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(*val); else return expected(unexpect, invoke(std::forward(f), error()));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. +Equivalent to: \tcode{if (has_value()) return G(*\exposid{val}); else return expected(unexpect, invoke(std::forward(f), error()));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. \end{itemdescr} \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &&; -template constexpr auto transform_error(F&& f) const&&; +template + constexpr auto transform_error(F&& f) &&; +template + constexpr auto transform_error(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -1245,7 +1087,7 @@ \pnum \effects -Equivalent to: \tcode{if (has_value()) return G(*val); else return expected(unexpect, invoke(std::forward(f), std::move(error())));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. +Equivalent to: \tcode{if (has_value()) return G(*\exposid{val}); else return expected(unexpect, invoke(std::forward(f), std::move(error())));} where \tcode{G2} is \tcode{remove_cv_t>} and \tcode{G} is \tcode{expected}. \end{itemdescr} \rSec3[expected.ref.eq]{Equality operators} @@ -1253,7 +1095,7 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const expected& y); + friend constexpr bool operator==(const expected& x, const expected& y); \end{itemdecl} \begin{itemdescr} @@ -1276,7 +1118,8 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} -template friend constexpr bool operator==(const expected& x, const T2& val); +template + friend constexpr bool operator==(const expected& x, const T2& val); \end{itemdecl} \begin{itemdescr} @@ -1290,13 +1133,13 @@ \pnum \returns -\tcode{x.has_value() && static_cast(*x == val)}. +\tcode{x.has_value() \&\& static_cast(*x == val)}. \end{itemdescr} \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const unexpected& e); + friend constexpr bool operator==(const expected& x, const unexpected& e); \end{itemdecl} \begin{itemdescr} @@ -1306,5 +1149,5 @@ \pnum \returns -\tcode{!x.has_value() && static_cast(x.error() == e.error())}. +\tcode{!x.has_value() \&\& static_cast(x.error() == e.error())}. \end{itemdescr} diff --git a/papers/wording/fragments/expected.unexpected.tex b/papers/wording/fragments/expected.unexpected.tex index dc005b7..cdeeaf7 100644 --- a/papers/wording/fragments/expected.unexpected.tex +++ b/papers/wording/fragments/expected.unexpected.tex @@ -6,24 +6,18 @@ namespace std { template class @\libglobal{unexpected}@ { - // [expected.un.general] para 2: ill-formed instantiations - public: constexpr unexpected(const unexpected&) = default; constexpr unexpected(unexpected&&) = default; template - requires(!is_same_v, unexpected> && - !is_same_v, in_place_t> && is_constructible_v) constexpr explicit unexpected(Err&& e) noexcept(is_nothrow_constructible_v); template - requires is_constructible_v constexpr explicit unexpected(in_place_t, Args&&... args) noexcept( is_nothrow_constructible_v); template - requires is_constructible_v&, Args...> constexpr explicit unexpected( in_place_t, initializer_list il, Args&&... args) noexcept(is_nothrow_constructible_v&, @@ -42,8 +36,8 @@ template friend constexpr bool operator==(const unexpected& x, const unexpected& y); - friend constexpr void swap(unexpected& x, unexpected& y) noexcept(noexcept(x.swap(y))) - requires is_swappable_v; + friend constexpr void swap(unexpected& x, + unexpected& y) noexcept(noexcept(x.swap(y))); private: E @\exposidnc{unex}@; // exposition only @@ -51,7 +45,6 @@ } \end{codeblock} -\begin{itemdescr} \pnum \mandates A program that instantiates the definition of \tcode{unexpected} for a non-object type other than an lvalue reference type, an array type, a specialization of \tcode{unexpected}, or a cv-qualified type is ill-formed. @@ -59,14 +52,13 @@ \pnum \remarks Subclause \iref{expected.unexpected} describes the class template \tcode{unexpected} that represents unexpected objects stored in \tcode{expected} objects. -\end{itemdescr} \rSec3[expected.un.cons]{Constructors} \indexlibraryctor{unexpected}% \begin{itemdecl} template -constexpr explicit unexpected(Err&& e) noexcept(is_nothrow_constructible_v); + constexpr explicit unexpected(Err&& e) noexcept(is_nothrow_constructible_v); \end{itemdecl} \begin{itemdescr} @@ -80,18 +72,17 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(e)}. +Direct-non-list-initializes \exposid{unex} with \tcode{std::forward(e)}. \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{unexpected}% \begin{itemdecl} template -constexpr explicit unexpected(in_place_t, Args&&... args) noexcept( - is_nothrow_constructible_v); + constexpr explicit unexpected(in_place_t, Args&&... args) noexcept(is_nothrow_constructible_v); \end{itemdecl} \begin{itemdescr} @@ -101,34 +92,32 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{std::forward(args)...}. \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{unexpected}% \begin{itemdecl} template -constexpr explicit unexpected( - in_place_t, initializer_list il, - Args&&... args) noexcept(is_nothrow_constructible_v&, - Args...>); + constexpr explicit unexpected(in_place_t, initializer_list il, + Args&&... args) noexcept(is_nothrow_constructible_v&, Args...>); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{il, std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{il, std::forward(args)...}. \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \rSec3[expected.un.obs]{Observers} @@ -136,35 +125,27 @@ \indexlibrarymember{error}{unexpected}% \begin{itemdecl} constexpr const E& error() const& noexcept; +constexpr E& error() & noexcept; \end{itemdecl} \begin{itemdescr} \pnum \returns -\tcode{unex}. +\exposid{unex}. \end{itemdescr} -\indexlibrarymember{error}{unexpected}% -\begin{itemdecl} -constexpr E& error() & noexcept; -\end{itemdecl} - \indexlibrarymember{error}{unexpected}% \begin{itemdecl} constexpr const E&& error() const&& noexcept; +constexpr E&& error() && noexcept; \end{itemdecl} \begin{itemdescr} \pnum \returns -\tcode{std::move(unex)}. +\tcode{std::move(\exposid{unex})}. \end{itemdescr} -\indexlibrarymember{error}{unexpected}% -\begin{itemdecl} -constexpr E&& error() && noexcept; -\end{itemdecl} - \rSec3[expected.un.swap]{Swap} \indexlibrarymember{swap}{unexpected}% @@ -179,7 +160,7 @@ \pnum \effects -Equivalent to: \tcode{using std::swap; swap(unex, other.unex);} +Equivalent to: \tcode{using std::swap; swap(\exposid{unex}, other.\exposid{unex});} \end{itemdescr} \indexlibraryglobal{swap}% @@ -202,7 +183,7 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const unexpected& x, const unexpected& y); + friend constexpr bool operator==(const unexpected& x, const unexpected& y); \end{itemdecl} \begin{itemdescr} @@ -247,19 +228,18 @@ } \end{codeblock} -\begin{itemdescr} \pnum \mandates -A program that instantiates the definition of \tcode{unexpected} for a referenced type that is not an object type, an array type, or a specialization of \tcode{unexpected} is ill-formed. +A program that instantiates the definition of \tcode{unexpected} for a referenced type that is not an object type, an array type, or a specialization of \tcode{unexpected} is ill-formed. \pnum \remarks -An object of type \tcode{unexpected} holds a pointer to an object of type \tcode{E}. The referenced object is not owned by the \tcode{unexpected} object. Unlike the primary template, \tcode{E} may be a cv-qualified type. -\end{itemdescr} +An object of type \tcode{unexpected} holds a pointer to an object of type \tcode{E}. The referenced object is not owned by the \tcode{unexpected} object. Unlike the primary template, \tcode{E} may be a cv-qualified type. \indexlibraryctor{unexpected}% \begin{itemdecl} -template constexpr explicit unexpected(G&& e) noexcept; +template + constexpr explicit unexpected(G&& e) noexcept; \end{itemdecl} \begin{itemdescr} @@ -268,32 +248,33 @@ \begin{itemize} \item \tcode{is_same_v, unexpected>} is \tcode{false}, \item \tcode{is_same_v, in_place_t>} is \tcode{false}, -\item \tcode{is_constructible_v} is \tcode{true}, and -\item \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\item \tcode{is_constructible_v} is \tcode{true}, and +\item \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \end{itemize} \pnum \effects -Initializes \tcode{unex} with \tcode{addressof(static_cast(std::forward(e)))}. +Initializes \exposid{unex} with \tcode{addressof(static_cast(std::forward(e)))}. \pnum \remarks -A constructor for which \tcode{reference_constructs_from_temporary_v} is \tcode{true} — one that would bind \tcode{E&} to a temporary — is defined as deleted. +A constructor for which \tcode{reference_constructs_from_temporary_v} is \tcode{true} — one that would bind \tcode{E\&} to a temporary — is defined as deleted. \end{itemdescr} \indexlibraryctor{unexpected}% \begin{itemdecl} -template constexpr explicit unexpected(in_place_t, G&& e) noexcept; +template + constexpr explicit unexpected(in_place_t, G&& e) noexcept; \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true} and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\tcode{is_constructible_v} is \tcode{true} and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \pnum \effects -Initializes \tcode{unex} with \tcode{addressof(static_cast(std::forward(e)))}. +Initializes \exposid{unex} with \tcode{addressof(static_cast(std::forward(e)))}. \end{itemdescr} \indexlibrarymember{error}{unexpected}% @@ -304,11 +285,11 @@ \begin{itemdescr} \pnum \returns -\tcode{*unex}. +\tcode{*\exposid{unex}}. \pnum \remarks -The reference returned is not \tcode{const}-qualified even when \tcode{*this} is \tcode{const}; the constness of the \tcode{unexpected} object does not propagate to the referenced object. +The reference returned is not \tcode{const}-qualified even when \tcode{*this} is \tcode{const}; the constness of the \tcode{unexpected} object does not propagate to the referenced object. \end{itemdescr} \indexlibrarymember{swap}{unexpected}% @@ -319,13 +300,13 @@ \begin{itemdescr} \pnum \effects -Exchanges \tcode{unex} and \tcode{other.unex}. +Exchanges \exposid{unex} and \tcode{other.\exposid{unex}}. \end{itemdescr} \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const unexpected& x, const unexpected& y); + friend constexpr bool operator==(const unexpected& x, const unexpected& y); \end{itemdecl} \begin{itemdescr} diff --git a/papers/wording/fragments/expected.void.tex b/papers/wording/fragments/expected.void.tex index eb981a4..d9f8ed4 100644 --- a/papers/wording/fragments/expected.void.tex +++ b/papers/wording/fragments/expected.void.tex @@ -16,221 +16,92 @@ template using rebind = expected; - // ------------------------------------------------------------------------- - // [expected.void.cons] Constructors - // ------------------------------------------------------------------------- - constexpr expected() noexcept; - // Unconstrained trivial-path candidate: see the primary template's copy - // constructor for why (the sole declaration when E is not copy - // constructible at all; subsumed by the non-trivial path otherwise). - - constexpr expected(const expected& rhs) noexcept(is_nothrow_copy_constructible_v) - requires(is_copy_constructible_v && !is_trivially_copy_constructible_v); + constexpr expected(const expected& rhs) noexcept( + is_nothrow_copy_constructible_v); - // Unconstrained; no explicit noexcept — see the primary template's move - // constructor for why. + constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v); - constexpr expected(expected&& rhs) noexcept(is_nothrow_move_constructible_v) - requires(is_move_constructible_v && !is_trivially_move_constructible_v); - - // Converting constructor from expected where is_void_v. Excludes U,G exactly - // matching this class's own void,E (the real copy/move constructors already handle - // that case) — instantiating this template for the self-referential case would - // otherwise probe unexpected's constructibility from this very class, which some - // standard library implementations of reference_constructs_from_temporary_v resolve - // as a circular constraint. template - requires(is_void_v && !is_reference_v && !is_same_v && - is_constructible_v && - !is_constructible_v, expected&> && - !is_constructible_v, expected&&> && - !is_constructible_v, const expected&> && - !is_constructible_v, const expected&&>) constexpr explicit(!is_convertible_v) expected(const expected& rhs); template - requires(is_void_v && !is_reference_v && !is_same_v && - is_constructible_v && - !is_constructible_v, expected&> && - !is_constructible_v, expected&&> && - !is_constructible_v, const expected&> && - !is_constructible_v, const expected&&>) constexpr explicit(!is_convertible_v) expected(expected&& rhs); - // Constructor from unexpected const& / && — value-E path template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(const unexpected& e); template - requires(!is_reference_v && is_constructible_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e); - // Constructor from unexpected — reference-E path. Allowed only when G is itself a - // reference, so e.error() refers to an external object and binding E& cannot dangle. - // No const_cast needed. template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) + expected(const unexpected& e) noexcept; template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; - // Deleted for reference E with value G: the referent lives inside the temporary - // unexpected, so binding E& to it would dangle once the source is destroyed. Use - // (unexpect, lvalue) instead. - template - requires(is_reference_v && !is_reference_v) - constexpr expected(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would " - "dangle — use unexpected"); + template constexpr expected(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected(unexpected&&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot construct from unexpected; the value would " - "dangle — use unexpected"); + constexpr expected(unexpected&&) = delete; - // In-place constructor for value (no args, just marks has-value) constexpr explicit expected(in_place_t) noexcept; - // In-place constructor for error - template - requires(is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr explicit expected(unexpect_t, Args&&... args); + template constexpr explicit expected(unexpect_t, Args&&... args); - // Deleted: single argument would bind E& to a temporary — dangling prevention - template - requires(@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " - "temporary that dangles; pass an lvalue reference"); + template constexpr expected(unexpect_t, Args&&...) = delete; - // Deleted catch-all: reference E, argument neither constructible nor a dangling case - // (e.g. binding a non-const E& from a const lvalue). template requires(is_reference_v && !is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) - constexpr expected(unexpect_t, Args&&...) = BEMAN_EXPECTED_DELETE_MSG( - "expected: no viable conversion from the given argument(s) to E&"); + constexpr expected(unexpect_t, Args&&...) = delete; - // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); template - requires is_reference_v - constexpr expected(unexpect_t, initializer_list, Args&&...) = - BEMAN_EXPECTED_DELETE_MSG( - "expected: initializer-list error construction cannot bind a " - "reference; pass an lvalue reference"); - - // Converting constructor from expected — reference-E path only. G is itself - // a reference to an external object, so binding E& to it cannot dangle regardless of - // the source's value category, provided the reference conversion itself does not - // materialize a temporary (e.g. a base-from-derived or qualification conversion is - // fine; a user-defined conversion that returns by value is not). Mirrors the - // unexpected reference-E path above. + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; + template - requires(is_reference_v && is_convertible_v && - !reference_constructs_from_temporary_v) - constexpr explicit(!is_convertible_v) expected(const expected& rhs); + constexpr explicit(!is_convertible_v) + expected(const expected& rhs); template - requires(is_reference_v && is_convertible_v && - !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(expected&& rhs); - // ------------------------------------------------------------------------- - // [expected.void.dtor] Destructor - // ------------------------------------------------------------------------- - constexpr ~expected(); - // ------------------------------------------------------------------------- - // [expected.void.assign] Assignment - // ------------------------------------------------------------------------- - - // Copy assignment (trivial path) - - // Copy assignment (non-trivial path) constexpr expected& operator=(const expected& rhs) noexcept( - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v) - requires((is_reference_v || - (is_copy_constructible_v && is_copy_assignable_v)) && - !(is_trivially_copy_constructible_v && - is_trivially_copy_assignable_v && is_trivially_destructible_v)); - - // Move assignment (trivial path) + is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); - // Move assignment (non-trivial path) constexpr expected& operator=(expected&& rhs) noexcept( - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v) - requires((is_reference_v || - (is_move_constructible_v && is_move_assignable_v)) && - !(is_trivially_move_constructible_v && - is_trivially_move_assignable_v && is_trivially_destructible_v)); + is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); - // Assignment from unexpected — value-E path. - template - requires(!is_reference_v && is_constructible_v && - is_assignable_v) - constexpr expected& operator=(const unexpected& e); + template constexpr expected& operator=(const unexpected& e); - template - requires(!is_reference_v && is_constructible_v && is_assignable_v) - constexpr expected& operator=(unexpected&& e); + template constexpr expected& operator=(unexpected&& e); - // Rebinding assignment for reference E from reference G — binds unex_ to the external - // referent. - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(const unexpected& e); + template constexpr expected& operator=(const unexpected& e); - template - requires(is_reference_v && is_reference_v && is_constructible_v && - !reference_constructs_from_temporary_v) - constexpr expected& operator=(unexpected&& e); + template constexpr expected& operator=(unexpected&& e); - // Deleted for reference E with value G: would bind E& to storage inside the temporary - // unexpected. - template - requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot assign from unexpected; the value would dangle " - "— use unexpected"); + template constexpr expected& operator=(const unexpected&) = delete; template requires(is_reference_v && !is_reference_v) - constexpr expected& operator=(unexpected&&) = BEMAN_EXPECTED_DELETE_MSG( - "expected: cannot assign from unexpected; the value would dangle " - "— use unexpected"); + constexpr expected& operator=(unexpected&&) = delete; constexpr void emplace() noexcept; - // ------------------------------------------------------------------------- - // [expected.void.swap] Swap - // ------------------------------------------------------------------------- - constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && (is_reference_v || - is_nothrow_swappable_v)) - requires((is_reference_v || is_swappable_v) && is_move_constructible_v); - - friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))) - requires((is_reference_v || is_swappable_v) && is_move_constructible_v); + is_nothrow_swappable_v)); - // ------------------------------------------------------------------------- - // [expected.void.obs] Observers - // ------------------------------------------------------------------------- + friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y))); constexpr explicit operator bool() const noexcept; constexpr bool has_value() const noexcept; @@ -240,78 +111,40 @@ constexpr void value() const&; constexpr void value() &&; - // error() — shallow const for reference E: always returns E& regardless of const on - // expected constexpr const E& error() const& noexcept; constexpr E& error() & noexcept; constexpr const E&& error() const&& noexcept; constexpr E&& error() && noexcept; template - requires(is_copy_constructible_v>> && - is_convertible_v>>) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; template - requires(is_move_constructible_v>> && - is_convertible_v>>) constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; - // Deleted: value_or is not available for void expected. Gated to reference E only so - // that, for value E, no value_or overload is declared at all (there is nothing to - // delete against). - template - requires is_reference_v - constexpr void value_or(U&&) const = BEMAN_EXPECTED_DELETE_MSG( - "expected: value_or is not defined for void value_type; there is no " - "value to fall back from — use has_value()/error()"); - - // ------------------------------------------------------------------------- - // [expected.void.monadic] Monadic operations - // ------------------------------------------------------------------------- - - template - requires is_constructible_v - constexpr auto and_then(F&& f) &; - template - requires is_constructible_v - constexpr auto and_then(F&& f) &&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&; - template - requires is_constructible_v - constexpr auto and_then(F&& f) const&&; + template constexpr void value_or(U&&) const = delete; + + template 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 - requires is_constructible_v - constexpr auto transform(F&& f) &; - template - requires is_constructible_v - constexpr auto transform(F&& f) &&; - template - requires is_constructible_v - constexpr auto transform(F&& f) const&; - template - requires is_constructible_v - constexpr auto transform(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 operators (hidden friends) - // ------------------------------------------------------------------------- - template - requires is_void_v friend constexpr bool operator==(const expected& x, const expected& y); template @@ -326,15 +159,13 @@ } \end{codeblock} -\begin{itemdescr} \pnum \mandates A program that instantiates the definition of \tcode{expected} with an \tcode{E} that is not a valid template argument for \tcode{unexpected} is ill-formed. \pnum \remarks -Any object of type \tcode{expected} either represents a value of type \tcode{T}, or contains a value of type \tcode{E} nested within it. Member \tcode{has_val} indicates whether the \tcode{expected} object represents a value of type \tcode{T}. When \tcode{has_value()} is \tcode{false}, the error is \tcode{unex.error()}. -\end{itemdescr} +Any object of type \tcode{expected} either represents a value of type \tcode{T}, or contains a value of type \tcode{E} nested within it. Member \tcode{has_val} indicates whether the \tcode{expected} object represents a value of type \tcode{T}. When \tcode{has_value()} is \tcode{false}, the error is \tcode{\exposid{unex}.error()}. \rSec3[expected.void.cons]{Constructors} @@ -361,7 +192,7 @@ \pnum \effects -If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -369,7 +200,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \pnum \remarks @@ -388,7 +219,7 @@ \pnum \effects -If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \tcode{unex} with \tcode{std::move(rhs.error())}. +If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \exposid{unex} with \tcode{std::move(rhs.error())}. \pnum \ensures @@ -396,7 +227,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \pnum \remarks @@ -406,19 +237,19 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const expected& rhs); + constexpr explicit(!is_convertible_v) expected(const expected& rhs); template -constexpr explicit(!is_convertible_v) expected(expected&& rhs); + constexpr explicit(!is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_void_v} is \tcode{true}; and \tcode{is_constructible_v} is \tcode{true}; and \tcode{is_constructible_v, expected&>} is \tcode{false}; and \tcode{is_constructible_v, expected>} is \tcode{false}; and \tcode{is_constructible_v, const expected&>} is \tcode{false}; and \tcode{is_constructible_v, const expected>} is \tcode{false}. +\tcode{is_void_v} is \tcode{true}; and \tcode{is_constructible_v} is \tcode{true}; and \tcode{is_constructible_v, expected\&>} is \tcode{false}; and \tcode{is_constructible_v, expected>} is \tcode{false}; and \tcode{is_constructible_v, const expected\&>} is \tcode{false}; and \tcode{is_constructible_v, const expected>} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -426,25 +257,25 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e); + constexpr explicit(!is_convertible_v) expected(const unexpected& e); template -constexpr explicit(!is_convertible_v) expected(unexpected&& e); + constexpr explicit(!is_convertible_v) expected(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{e.error()}. +Direct-non-list-initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -452,15 +283,15 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; + constexpr explicit(!is_convertible_v) expected(const unexpected& e) noexcept; template -constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; + constexpr explicit(!is_convertible_v) expected(unexpected&& e) noexcept; \end{itemdecl} \begin{itemdescr} @@ -470,7 +301,7 @@ \pnum \effects -Initializes \tcode{unex} with \tcode{e.error()}. +Initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -483,7 +314,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -493,7 +325,7 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: the referent would live inside the (possibly temporary) source \tcode{unexpected} object, and binding \tcode{E\&} to it would dangle. Use an \tcode{unexpected} holding an external object instead. \end{itemdescr} \indexlibraryctor{expected}% @@ -509,7 +341,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr explicit expected(unexpect_t, Args&&... args); +template + constexpr explicit expected(unexpect_t, Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -519,7 +352,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{std::forward(args)...}. \pnum \ensures @@ -527,12 +360,13 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -542,23 +376,23 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. +When \tcode{E} is a reference type, an overload with the same parameter types is defined as deleted if the single argument would bind \tcode{E\&} to a temporary, or if it is otherwise not usable to construct \tcode{E}. \end{itemdescr} \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); + constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v&, Args...>} is \tcode{true}. +\tcode{is_reference_v} is \tcode{false}, and \tcode{is_constructible_v\&, Args...>} is \tcode{true}. \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{il, std::forward(args)...}. +Direct-non-list-initializes \exposid{unex} with \tcode{il, std::forward(args)...}. \pnum \ensures @@ -566,7 +400,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \pnum \remarks @@ -576,7 +410,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -592,19 +426,19 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr explicit(!is_convertible_v) expected(const expected& rhs); + constexpr explicit(!is_convertible_v) expected(const expected& rhs); template -constexpr explicit(!is_convertible_v) expected(expected&& rhs); + constexpr explicit(!is_convertible_v) expected(expected&& rhs); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_convertible_v} is \tcode{true}; and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. +\tcode{is_convertible_v} is \tcode{true}; and \tcode{reference_constructs_from_temporary_v} is \tcode{false}. \pnum \effects -If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \tcode{unex} with \tcode{rhs.error()}. +If \tcode{rhs.has_value()} is \tcode{false}, direct-non-list-initializes \exposid{unex} with \tcode{rhs.error()}. \pnum \ensures @@ -625,7 +459,7 @@ \begin{itemdescr} \pnum \effects -If \tcode{has_value()} is \tcode{false}, destroys \tcode{unex}. +If \tcode{has_value()} is \tcode{false}, destroys \exposid{unex}. \pnum \remarks @@ -636,18 +470,18 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -constexpr expected& operator=(const expected& rhs) noexcept( - is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); +constexpr expected& operator=(const expected& rhs) noexcept(is_nothrow_copy_constructible_v && + is_nothrow_copy_assignable_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v || (is_copy_constructible_v && is_copy_assignable_v)} is \tcode{true} and \tcode{(is_trivially_copy_constructible_v && is_trivially_copy_assignable_v && is_trivially_destructible_v)} is \tcode{false}. +\tcode{is_reference_v || (is_copy_constructible_v \&\& is_copy_assignable_v)} is \tcode{true} and \tcode{(is_trivially_copy_constructible_v \&\& is_trivially_copy_assignable_v \&\& is_trivially_destructible_v)} is \tcode{false}. \pnum \effects -If \tcode{this->has_value() && rhs.has_value()}, no effects. Otherwise, if \tcode{this->has_value()}, equivalent to: \tcode{construct_at(addressof(unex), rhs.unex); has_val = false;} Otherwise, if \tcode{rhs.has_value()}, destroys \tcode{unex} and sets \tcode{has_val} to \tcode{true}. Otherwise, equivalent to \tcode{unex = rhs.unex}. +If \tcode{this->has_value() \&\& rhs.has_value()}, no effects. Otherwise, if \tcode{this->has_value()}, equivalent to: \tcode{construct_at(addressof(\exposid{unex}), rhs.\exposid{unex}); has_val = false;} Otherwise, if \tcode{rhs.has_value()}, destroys \exposid{unex} and sets \tcode{has_val} to \tcode{true}. Otherwise, equivalent to \tcode{\exposid{unex} = rhs.\exposid{unex}}. \pnum \returns @@ -660,18 +494,18 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -constexpr expected& operator=(expected&& rhs) noexcept( - is_nothrow_move_constructible_v && is_nothrow_move_assignable_v); +constexpr expected& operator=(expected&& rhs) noexcept(is_nothrow_move_constructible_v && + is_nothrow_move_assignable_v); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_reference_v || (is_move_constructible_v && is_move_assignable_v)} is \tcode{true} and \tcode{(is_trivially_move_constructible_v && is_trivially_move_assignable_v && is_trivially_destructible_v)} is \tcode{false}. +\tcode{is_reference_v || (is_move_constructible_v \&\& is_move_assignable_v)} is \tcode{true} and \tcode{(is_trivially_move_constructible_v \&\& is_trivially_move_assignable_v \&\& is_trivially_destructible_v)} is \tcode{false}. \pnum \effects -If \tcode{this->has_value() && rhs.has_value()}, no effects. Otherwise, if \tcode{this->has_value()}, equivalent to: \tcode{construct_at(addressof(unex), std::move(rhs.unex)); has_val = false;} Otherwise, if \tcode{rhs.has_value()}, destroys \tcode{unex} and sets \tcode{has_val} to \tcode{true}. Otherwise, equivalent to \tcode{unex = std::move(rhs.unex)}. +If \tcode{this->has_value() \&\& rhs.has_value()}, no effects. Otherwise, if \tcode{this->has_value()}, equivalent to: \tcode{construct_at(addressof(\exposid{unex}), std::move(rhs.\exposid{unex})); has_val = false;} Otherwise, if \tcode{rhs.has_value()}, destroys \exposid{unex} and sets \tcode{has_val} to \tcode{true}. Otherwise, equivalent to \tcode{\exposid{unex} = std::move(rhs.\exposid{unex})}. \pnum \returns @@ -679,23 +513,25 @@ \pnum \remarks -The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v && is_nothrow_move_assignable_v}. This operator is trivial if \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, and \tcode{is_trivially_destructible_v} are all \tcode{true}. +The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v \&\& is_nothrow_move_assignable_v}. This operator is trivial if \tcode{is_trivially_move_constructible_v}, \tcode{is_trivially_move_assignable_v}, and \tcode{is_trivially_destructible_v} are all \tcode{true}. \end{itemdescr} \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true} and \tcode{is_assignable_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true} and \tcode{is_assignable_v} is \tcode{true}. \pnum \effects -If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{construct_at(addressof(unex), e.error()); has_val = false;} Otherwise, equivalent to: \tcode{unex = unexpected(e.error());} +If \tcode{has_value()} is \tcode{true}, equivalent to: \tcode{construct_at(addressof(\exposid{unex}), e.error()); has_val = false;} Otherwise, equivalent to: \tcode{\exposid{unex} = unexpected(e.error());} \pnum \returns @@ -704,8 +540,10 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected& e); -template constexpr expected& operator=(unexpected&& e); +template + constexpr expected& operator=(const unexpected& e); +template + constexpr expected& operator=(unexpected&& e); \end{itemdecl} \begin{itemdescr} @@ -715,7 +553,7 @@ \pnum \effects -Rebinds \tcode{unex} to refer to the same object as \tcode{e.error()}. +Rebinds \exposid{unex} to refer to the same object as \tcode{e.error()}. \pnum \ensures @@ -732,7 +570,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -742,7 +581,7 @@ \pnum \remarks -When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \tcode{unex} to \tcode{unexpected}'s temporary storage. +When \tcode{E} is a reference type, an overload taking \tcode{unexpected} for a non-reference \tcode{G} is defined as deleted: it would rebind \exposid{unex} to \tcode{unexpected}'s temporary storage. \end{itemdescr} \indexlibrarymember{emplace}{expected}% @@ -753,7 +592,7 @@ \begin{itemdescr} \pnum \effects -If \tcode{has_value()} is \tcode{false}, destroys \tcode{unex} and sets \tcode{has_val} to \tcode{true}. +If \tcode{has_value()} is \tcode{false}, destroys \exposid{unex} and sets \tcode{has_val} to \tcode{true}. \end{itemdescr} \rSec3[expected.void.swap]{Swap} @@ -761,8 +600,7 @@ \indexlibrarymember{swap}{expected}% \begin{itemdecl} constexpr void swap(expected& rhs) noexcept(is_nothrow_move_constructible_v && - (is_reference_v || - is_nothrow_swappable_v)); + (is_reference_v || is_nothrow_swappable_v)); \end{itemdecl} \begin{itemdescr} @@ -772,7 +610,7 @@ \pnum \effects -If \tcode{this->has_value()} and \tcode{rhs.has_value()}, no effects. If neither \tcode{*this} nor \tcode{rhs} contains a value, equivalent to \tcode{using std::swap; swap(unex, rhs.unex);}. If \tcode{rhs.has_value()} is \tcode{false} and \tcode{this->has_value()} is \tcode{true}, initializes \tcode{rhs.unex} from \tcode{std::move(unex)}, destroys \tcode{unex}, and leaves \tcode{has_value()} \tcode{false} and \tcode{rhs.has_value()} \tcode{true}. If \tcode{rhs.has_value()} is \tcode{true} and \tcode{this->has_value()} is \tcode{false}, equivalent to \tcode{rhs.swap(*this)}. +If \tcode{this->has_value()} and \tcode{rhs.has_value()}, no effects. If neither \tcode{*this} nor \tcode{rhs} contains a value, equivalent to \tcode{using std::swap; swap(\exposid{unex}, rhs.\exposid{unex});}. If \tcode{rhs.has_value()} is \tcode{false} and \tcode{this->has_value()} is \tcode{true}, initializes \tcode{rhs.\exposid{unex}} from \tcode{std::move(\exposid{unex})}, destroys \exposid{unex}, and leaves \tcode{has_value()} \tcode{false} and \tcode{rhs.has_value()} \tcode{true}. If \tcode{rhs.has_value()} is \tcode{true} and \tcode{this->has_value()} is \tcode{false}, equivalent to \tcode{rhs.swap(*this)}. \pnum \throws @@ -780,7 +618,7 @@ \pnum \remarks -The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v && (is_reference_v || is_nothrow_swappable_v)}. +The exception specification is equivalent to \tcode{is_nothrow_move_constructible_v \&\& (is_reference_v || is_nothrow_swappable_v)}. \end{itemdescr} \indexlibraryglobal{swap}% @@ -867,7 +705,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -883,13 +721,13 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{error_or}{expected}% \begin{itemdecl} template -constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) const&; \end{itemdecl} \begin{itemdescr} @@ -899,7 +737,7 @@ \pnum \mandates -\tcode{is_copy_constructible_v} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_copy_constructible_v<\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. \pnum \returns @@ -908,7 +746,8 @@ \indexlibrarymember{error_or}{expected}% \begin{itemdecl} -template constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; +template + constexpr @\exposidnc{error-value-type}@ error_or(G&& def) &&; \end{itemdecl} \begin{itemdescr} @@ -918,7 +757,7 @@ \pnum \mandates -\tcode{is_move_constructible_v} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. +\tcode{is_move_constructible_v<\exposid{error-value-type}>} is \tcode{true} and \tcode{is_convertible_v} is \tcode{true}. \pnum \returns @@ -927,7 +766,8 @@ \indexlibrarymember{value_or}{expected}% \begin{itemdecl} -template constexpr void value_or(U&&) const; +template + constexpr void value_or(U&&) const = delete; \end{itemdecl} \begin{itemdescr} @@ -944,8 +784,10 @@ \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &; -template constexpr auto and_then(F&& f) const&; +template + constexpr auto and_then(F&& f) &; +template + constexpr auto and_then(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -964,8 +806,10 @@ \indexlibrarymember{and_then}{expected}% \begin{itemdecl} -template constexpr auto and_then(F&& f) &&; -template constexpr auto and_then(F&& f) const&&; +template + constexpr auto and_then(F&& f) &&; +template + constexpr auto and_then(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -984,8 +828,10 @@ \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &; -template constexpr auto or_else(F&& f) const&; +template + constexpr auto or_else(F&& f) &; +template + constexpr auto or_else(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -1000,8 +846,10 @@ \indexlibrarymember{or_else}{expected}% \begin{itemdecl} -template constexpr auto or_else(F&& f) &&; -template constexpr auto or_else(F&& f) const&&; +template + constexpr auto or_else(F&& f) &&; +template + constexpr auto or_else(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -1016,8 +864,10 @@ \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &; -template constexpr auto transform(F&& f) const&; +template + constexpr auto transform(F&& f) &; +template + constexpr auto transform(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -1036,8 +886,10 @@ \indexlibrarymember{transform}{expected}% \begin{itemdecl} -template constexpr auto transform(F&& f) &&; -template constexpr auto transform(F&& f) const&&; +template + constexpr auto transform(F&& f) &&; +template + constexpr auto transform(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -1056,8 +908,10 @@ \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &; -template constexpr auto transform_error(F&& f) const&; +template + constexpr auto transform_error(F&& f) &; +template + constexpr auto transform_error(F&& f) const&; \end{itemdecl} \begin{itemdescr} @@ -1067,13 +921,15 @@ \pnum \returns -If \tcode{has_value()} is \tcode{true}, \tcode{expected()}; otherwise, an \tcode{expected} object whose \tcode{has_val} member is \tcode{false} and \tcode{unex} member is direct-non-list-initialized with \tcode{invoke(std::forward(f), error())}. +If \tcode{has_value()} is \tcode{true}, \tcode{expected()}; otherwise, an \tcode{expected} object whose \tcode{has_val} member is \tcode{false} and \exposid{unex} member is direct-non-list-initialized with \tcode{invoke(std::forward(f), error())}. \end{itemdescr} \indexlibrarymember{transform_error}{expected}% \begin{itemdecl} -template constexpr auto transform_error(F&& f) &&; -template constexpr auto transform_error(F&& f) const&&; +template + constexpr auto transform_error(F&& f) &&; +template + constexpr auto transform_error(F&& f) const&&; \end{itemdecl} \begin{itemdescr} @@ -1083,7 +939,7 @@ \pnum \returns -If \tcode{has_value()} is \tcode{true}, \tcode{expected()}; otherwise, an \tcode{expected} object whose \tcode{has_val} member is \tcode{false} and \tcode{unex} member is direct-non-list-initialized with \tcode{invoke(std::forward(f), std::move(error()))}. +If \tcode{has_value()} is \tcode{true}, \tcode{expected()}; otherwise, an \tcode{expected} object whose \tcode{has_val} member is \tcode{false} and \exposid{unex} member is direct-non-list-initialized with \tcode{invoke(std::forward(f), std::move(error()))}. \end{itemdescr} \rSec3[expected.void.eq]{Equality operators} @@ -1091,7 +947,7 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const expected& y); + friend constexpr bool operator==(const expected& x, const expected& y); \end{itemdecl} \begin{itemdescr} @@ -1111,7 +967,7 @@ \indexlibraryglobal{operator==}% \begin{itemdecl} template -friend constexpr bool operator==(const expected& x, const unexpected& e); + friend constexpr bool operator==(const expected& x, const unexpected& e); \end{itemdecl} \begin{itemdescr} @@ -1121,5 +977,5 @@ \pnum \returns -\tcode{!x.has_value() && static_cast(x.error() == e.error())}. +\tcode{!x.has_value() \&\& static_cast(x.error() == e.error())}. \end{itemdescr}