From 1e623ce355c2cc974bb260ffc57bafabac47694b Mon Sep 17 00:00:00 2001 From: Steve Downey Date: Mon, 16 Nov 2026 10:39:15 -0500 Subject: [PATCH 1/3] Add a clean-wording goal for regenerating after a specgen change The wording rules compare the fragments with the annotated headers. A new specgen renders the same headers differently without touching one, so make finds nothing to do and the checked-in wording stays as the old specgen wrote it. `make -B wording` does not help: .DEFAULT then hands every prerequisite that has no rule of its own, the headers and the makefile among them, to cmake as a target. clean-wording deletes the fragments, expected.tex, the *.root.tex files and the depfile, so that `make clean-wording wording` writes all of it again. The fragments and expected.tex are checked in, so the goal refuses to run when specgen is not found, and neither clean nor realclean depends on it. --- Makefile | 19 +++++++++++++++++++ papers/wording/README.md | 11 +++++++++++ 2 files changed, 30 insertions(+) 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. From 6df93b016872f69cc167dafd564269e953526392 Mon Sep 17 00:00:00 2001 From: Steve Downey Date: Mon, 16 Nov 2026 10:39:23 -0500 Subject: [PATCH 2/3] Regenerate the wording with specgen 0.23.0 The output of `make clean-wording wording`. No header changed, and no wording changed either: with whitespace ignored, the old and new fragments differ only in the ways listed here, all of them in how specgen renders the same headers. - A declaration following its template-head is indented, and long declarations, comments and string literals wrap at different points. - `&`, `{` and `}` are escaped inside \tcode. - Class-level remarks and mandates are no longer wrapped in an itemdescr. - In [expected.un.obs], the two pairs of error() overloads that share a Returns element are each stated as one itemdecl. --- papers/wording/expected.tex | 840 ++++++++++-------- papers/wording/fragments/expected.bad.tex | 2 - .../wording/fragments/expected.expected.tex | 289 +++--- papers/wording/fragments/expected.ref.tex | 276 +++--- .../wording/fragments/expected.unexpected.tex | 63 +- papers/wording/fragments/expected.void.tex | 210 +++-- 6 files changed, 914 insertions(+), 766 deletions(-) diff --git a/papers/wording/expected.tex b/papers/wording/expected.tex index 2d42b68..0afdf9c 100644 --- a/papers/wording/expected.tex +++ b/papers/wording/expected.tex @@ -33,7 +33,8 @@ template requires(!is_same_v, unexpected> && - !is_same_v, in_place_t> && is_constructible_v) + !is_same_v, in_place_t> && + is_constructible_v) constexpr explicit unexpected(Err&& e) noexcept(is_nothrow_constructible_v); template @@ -61,7 +62,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))) + friend constexpr void swap(unexpected& x, + unexpected& y) noexcept(noexcept(x.swap(y))) requires is_swappable_v; private: @@ -70,7 +72,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 +79,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} @@ -109,8 +109,7 @@ \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} @@ -130,16 +129,14 @@ \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 @@ -155,6 +152,7 @@ \indexlibrarymember{error}{unexpected}% \begin{itemdecl} constexpr const E& error() const& noexcept; +constexpr E& error() & noexcept; \end{itemdecl} \begin{itemdescr} @@ -163,14 +161,10 @@ \tcode{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} @@ -179,11 +173,6 @@ \tcode{std::move(unex)}. \end{itemdescr} -\indexlibrarymember{error}{unexpected}% -\begin{itemdecl} -constexpr E&& error() && noexcept; -\end{itemdecl} - \rSec3[expected.un.swap]{Swap} \indexlibrarymember{swap}{unexpected}% @@ -221,7 +210,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 +255,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 +275,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 \tcode{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 \tcode{unex} with \tcode{addressof(static_cast(std::forward(e)))}. \end{itemdescr} \indexlibrarymember{error}{unexpected}% @@ -327,7 +316,7 @@ \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}% @@ -344,7 +333,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} @@ -399,11 +388,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} @@ -529,8 +516,8 @@ 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) + 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)); @@ -573,8 +560,8 @@ 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. + // 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) @@ -606,14 +593,15 @@ 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. + // 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 && @@ -621,19 +609,19 @@ 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. + // 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"); + "expected: cannot construct from unexpected; the value would " + "dangle — use unexpected"); 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"); + "expected: cannot construct from unexpected; the value would " + "dangle — use unexpected"); // In-place constructor for value template @@ -657,8 +645,8 @@ BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " "temporary that dangles; pass an lvalue reference"); - // Deleted catch-all: reference E, argument neither constructible nor a dangling case - // (e.g. binding a non-const E& from a const lvalue). + // 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}@) @@ -667,7 +655,8 @@ // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) + requires(!is_reference_v && + is_constructible_v&, Args...>) constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); template @@ -740,7 +729,8 @@ 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_constructible_v || + is_nothrow_move_constructible_v || is_nothrow_move_constructible_v)) constexpr expected& operator=(U&& v); @@ -749,18 +739,21 @@ requires(!is_reference_v && is_constructible_v && is_assignable_v && (is_nothrow_constructible_v || - is_nothrow_move_constructible_v || is_nothrow_move_constructible_v)) + is_nothrow_move_constructible_v || + is_nothrow_move_constructible_v)) constexpr expected& operator=(const unexpected& e); template - requires(!is_reference_v && is_constructible_v && is_assignable_v && - (is_nothrow_constructible_v || is_nothrow_move_constructible_v || + 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. + // 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) @@ -771,19 +764,19 @@ !reference_constructs_from_temporary_v) constexpr expected& operator=(unexpected&& e); - // Deleted for reference E with value G: would rebind E& to unexpected's temporary - // storage. + // 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"); + constexpr expected& operator=(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( + "expected: cannot assign from unexpected; the value would dangle " + "— use unexpected"); 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&&) = BEMAN_EXPECTED_DELETE_MSG( + "expected: cannot assign from unexpected; the value would dangle " + "— use unexpected"); // Emplace: destroy current value/error, construct value in-place template @@ -805,14 +798,14 @@ 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)) - ; + (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)) - ; + (is_nothrow_move_constructible_v || + is_nothrow_move_constructible_v)); // ------------------------------------------------------------------------- // [expected.object.obs] Observers @@ -934,15 +927,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{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} @@ -997,7 +988,7 @@ \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 @@ -1037,14 +1028,13 @@ \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 @@ -1066,17 +1056,16 @@ \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 @@ -1094,17 +1083,15 @@ \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 @@ -1126,7 +1113,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} @@ -1150,19 +1137,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 -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(e.error())}. +Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(e.error())}. \pnum \ensures @@ -1176,9 +1163,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} @@ -1201,7 +1188,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -1211,12 +1199,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} @@ -1240,13 +1229,13 @@ \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 @@ -1263,7 +1252,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} @@ -1286,7 +1276,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -1296,19 +1287,19 @@ \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 @@ -1330,7 +1321,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -1372,7 +1363,7 @@ \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 @@ -1413,9 +1404,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 +1416,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{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. \pnum \returns @@ -1474,9 +1466,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 +1478,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{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. \pnum \returns @@ -1500,18 +1493,19 @@ \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 @@ -1524,14 +1518,16 @@ \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 @@ -1544,8 +1540,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} @@ -1572,7 +1570,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -1587,7 +1586,8 @@ \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 +1597,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(val)); \} else \{ destroy_at(addressof(unex)); has_val = true; \} return *construct_at(addressof(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(val)); \} else \{ destroy_at(addressof(unex)); has_val = true; \} return *construct_at(addressof(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} @@ -1648,7 +1646,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}% @@ -1809,7 +1807,8 @@ \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 +1823,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,7 +1840,7 @@ \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} @@ -1859,7 +1859,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} @@ -1880,8 +1881,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} @@ -1900,8 +1903,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} @@ -1920,8 +1925,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} @@ -1940,8 +1947,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} @@ -1960,8 +1969,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} @@ -1976,8 +1987,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} @@ -1992,8 +2005,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} @@ -2017,8 +2032,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} @@ -2045,7 +2062,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 +2081,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 +2096,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 +2112,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} @@ -2134,12 +2152,12 @@ 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. + // 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 && @@ -2168,13 +2186,14 @@ 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. + // 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 && @@ -2211,8 +2230,8 @@ BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " "temporary that dangles; pass an lvalue reference"); - // Deleted catch-all: reference E, argument neither constructible nor a dangling case - // (e.g. binding a non-const E& from a const lvalue). + // 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}@) @@ -2221,7 +2240,8 @@ // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) + requires(!is_reference_v && + is_constructible_v&, Args...>) constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); template @@ -2231,16 +2251,17 @@ "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. + // 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. 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 && @@ -2287,8 +2308,8 @@ requires(!is_reference_v && is_constructible_v && is_assignable_v) constexpr expected& operator=(unexpected&& e); - // Rebinding assignment for reference E from reference G — binds unex_ to the external - // referent. + // 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) @@ -2299,19 +2320,19 @@ !reference_constructs_from_temporary_v) constexpr expected& operator=(unexpected&& e); - // Deleted for reference E with value G: would bind E& to storage inside the temporary - // unexpected. + // 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"); + "expected: cannot assign from unexpected; the value would " + "dangle — use unexpected"); 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"); + "expected: cannot assign from unexpected; the value would " + "dangle — use unexpected"); constexpr void emplace() noexcept; @@ -2356,9 +2377,9 @@ 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). + // 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( @@ -2425,7 +2446,6 @@ } \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. @@ -2433,7 +2453,6 @@ \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} \rSec3[expected.void.cons]{Constructors} @@ -2505,15 +2524,15 @@ \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 @@ -2531,15 +2550,15 @@ \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 @@ -2557,9 +2576,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} @@ -2582,7 +2601,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -2592,7 +2612,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 +2628,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} @@ -2631,7 +2652,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -2641,19 +2663,19 @@ \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 @@ -2675,7 +2697,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -2691,15 +2713,15 @@ \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 @@ -2735,18 +2757,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(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}. \pnum \returns @@ -2759,18 +2781,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(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)}. \pnum \returns @@ -2778,19 +2800,21 @@ \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 @@ -2803,8 +2827,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} @@ -2831,7 +2857,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -2860,8 +2887,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} @@ -2879,7 +2905,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}% @@ -2988,7 +3014,7 @@ \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} @@ -3007,7 +3033,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} @@ -3026,7 +3053,8 @@ \indexlibrarymember{value_or}{expected}% \begin{itemdecl} -template constexpr void value_or(U&&) const; +template + constexpr void value_or(U&&) const; \end{itemdecl} \begin{itemdescr} @@ -3043,8 +3071,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 +3093,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 +3115,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 +3133,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 +3151,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 +3173,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 +3195,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} @@ -3171,8 +3213,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} @@ -3190,7 +3234,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 +3254,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 +3264,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} @@ -3274,7 +3318,8 @@ requires(!is_same_v, in_place_t> && !is_same_v, expected> && !@\exposidnc{is-unexpected-specialization}@>::value && - is_constructible_v && !reference_constructs_from_temporary_v) + is_constructible_v && + !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(U&& u) noexcept(is_nothrow_constructible_v); @@ -3282,8 +3327,8 @@ 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"); + BEMAN_EXPECTED_DELETE_MSG("expected: argument would bind a temporary " + "that dangles; pass an lvalue reference"); // Converting constructor from expected (copy) — value-E path template @@ -3296,7 +3341,8 @@ // Converting constructor from expected (move) — value-E path template requires(!is_reference_v && is_constructible_v && - is_constructible_v && !reference_constructs_from_temporary_v) + is_constructible_v && + !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); @@ -3323,14 +3369,15 @@ 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. + // 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 && @@ -3338,8 +3385,8 @@ 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. + // 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( @@ -3364,7 +3411,8 @@ BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " "temporary that dangles; pass an lvalue reference"); - // Deleted catch-all: reference E, argument neither constructible nor a dangling case + // Deleted catch-all: reference E, argument neither constructible nor a dangling + // case template requires(is_reference_v && !is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) @@ -3373,14 +3421,16 @@ // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) + 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"); + BEMAN_EXPECTED_DELETE_MSG( + "expected: initializer-list error construction cannot bind a " + "reference; pass an lvalue reference"); // ------------------------------------------------------------------------- // Destructor @@ -3429,7 +3479,8 @@ template requires(!is_same_v, expected> && !@\exposidnc{is-unexpected-specialization}@>::value && - is_constructible_v && !reference_constructs_from_temporary_v) + is_constructible_v && + !reference_constructs_from_temporary_v) constexpr expected& operator=(U&& u); // Assignment from unexpected — value-E path @@ -3442,8 +3493,8 @@ requires(!is_reference_v && is_constructible_v && is_assignable_v) constexpr expected& operator=(unexpected&& e); - // Rebinding assignment for reference E from reference G — binds unex_ to the external - // referent. + // 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) @@ -3454,23 +3505,24 @@ !reference_constructs_from_temporary_v) constexpr expected& operator=(unexpected&& e); - // Deleted for reference E with value G: would rebind E& to unexpected's temporary - // storage. + // 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"); + "expected: cannot assign from unexpected; the value would dangle " + "— use unexpected"); 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"); + "expected: cannot assign from unexpected; the value would dangle " + "— use unexpected"); // emplace — rebind the reference template - requires(is_constructible_v && !reference_constructs_from_temporary_v) + requires(is_constructible_v && + !reference_constructs_from_temporary_v) constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v); // ------------------------------------------------------------------------- @@ -3510,8 +3562,8 @@ // 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. + // 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>>) @@ -3589,15 +3641,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. \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 \tcode{val} points to the referenced object, which is not owned by the \tcode{expected} object. Otherwise, the error is \tcode{unex.error()}. \rSec3[expected.ref.cons]{Constructors} @@ -3609,7 +3659,7 @@ \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}% @@ -3676,30 +3726,30 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(in_place_t, Args&&...); +template + constexpr expected(in_place_t, Args&&...); \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 \tcode{val} with \tcode{addressof(r)}. \pnum \ensures @@ -3708,33 +3758,32 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(U&&); +template + constexpr expected(U&&); \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 @@ -3744,17 +3793,15 @@ \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 @@ -3768,15 +3815,15 @@ \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 @@ -3790,9 +3837,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} @@ -3815,7 +3862,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -3825,12 +3873,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} @@ -3849,7 +3898,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -3859,19 +3909,19 @@ \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 @@ -3889,7 +3939,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -3964,21 +4014,21 @@ \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 @@ -4018,17 +4068,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 \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. \pnum \returns @@ -4037,14 +4088,16 @@ \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 @@ -4057,8 +4110,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} @@ -4081,7 +4136,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -4097,17 +4153,17 @@ \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 \tcode{unex} first. Sets \tcode{val} to \tcode{addressof(r)} and \tcode{has_val} to \tcode{true}. \pnum \returns @@ -4119,8 +4175,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} @@ -4134,7 +4189,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}% @@ -4170,7 +4225,7 @@ \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}% @@ -4189,7 +4244,7 @@ \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}% @@ -4273,7 +4328,8 @@ \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,7 +4339,7 @@ \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 @@ -4293,7 +4349,7 @@ \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 +4364,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 +4382,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 +4395,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), *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,23 +4421,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), *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), *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 @@ -4385,14 +4448,16 @@ \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 @@ -4401,8 +4466,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} @@ -4412,13 +4479,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), *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 +4497,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), *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 +4520,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(*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 +4543,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(*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 +4551,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 +4574,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 +4589,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 +4605,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..d146504 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} diff --git a/papers/wording/fragments/expected.expected.tex b/papers/wording/fragments/expected.expected.tex index b106da0..9f10838 100644 --- a/papers/wording/fragments/expected.expected.tex +++ b/papers/wording/fragments/expected.expected.tex @@ -32,8 +32,8 @@ 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) + 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)); @@ -76,8 +76,8 @@ 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. + // 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) @@ -109,14 +109,15 @@ 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. + // 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 && @@ -124,19 +125,19 @@ 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. + // 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"); + "expected: cannot construct from unexpected; the value would " + "dangle — use unexpected"); 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"); + "expected: cannot construct from unexpected; the value would " + "dangle — use unexpected"); // In-place constructor for value template @@ -160,8 +161,8 @@ BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " "temporary that dangles; pass an lvalue reference"); - // Deleted catch-all: reference E, argument neither constructible nor a dangling case - // (e.g. binding a non-const E& from a const lvalue). + // 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}@) @@ -170,7 +171,8 @@ // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) + requires(!is_reference_v && + is_constructible_v&, Args...>) constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); template @@ -243,7 +245,8 @@ 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_constructible_v || + is_nothrow_move_constructible_v || is_nothrow_move_constructible_v)) constexpr expected& operator=(U&& v); @@ -252,18 +255,21 @@ requires(!is_reference_v && is_constructible_v && is_assignable_v && (is_nothrow_constructible_v || - is_nothrow_move_constructible_v || is_nothrow_move_constructible_v)) + is_nothrow_move_constructible_v || + is_nothrow_move_constructible_v)) constexpr expected& operator=(const unexpected& e); template - requires(!is_reference_v && is_constructible_v && is_assignable_v && - (is_nothrow_constructible_v || is_nothrow_move_constructible_v || + 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. + // 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) @@ -274,19 +280,19 @@ !reference_constructs_from_temporary_v) constexpr expected& operator=(unexpected&& e); - // Deleted for reference E with value G: would rebind E& to unexpected's temporary - // storage. + // 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"); + constexpr expected& operator=(const unexpected&) = BEMAN_EXPECTED_DELETE_MSG( + "expected: cannot assign from unexpected; the value would dangle " + "— use unexpected"); 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&&) = BEMAN_EXPECTED_DELETE_MSG( + "expected: cannot assign from unexpected; the value would dangle " + "— use unexpected"); // Emplace: destroy current value/error, construct value in-place template @@ -308,14 +314,14 @@ 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)) - ; + (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)) - ; + (is_nothrow_move_constructible_v || + is_nothrow_move_constructible_v)); // ------------------------------------------------------------------------- // [expected.object.obs] Observers @@ -437,15 +443,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{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} @@ -500,7 +504,7 @@ \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 @@ -540,14 +544,13 @@ \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 @@ -569,17 +572,16 @@ \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 @@ -597,17 +599,15 @@ \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 @@ -629,7 +629,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} @@ -653,19 +653,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 -Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(e.error())}. +Direct-non-list-initializes \tcode{unex} with \tcode{std::forward(e.error())}. \pnum \ensures @@ -679,9 +679,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} @@ -704,7 +704,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -714,12 +715,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} @@ -743,13 +745,13 @@ \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 @@ -766,7 +768,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} @@ -789,7 +792,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -799,19 +803,19 @@ \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 @@ -833,7 +837,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -875,7 +879,7 @@ \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 @@ -916,9 +920,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 +932,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{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. \pnum \returns @@ -977,9 +982,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 +994,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{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. \pnum \returns @@ -1003,18 +1009,19 @@ \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 @@ -1027,14 +1034,16 @@ \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 @@ -1047,8 +1056,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} @@ -1075,7 +1086,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -1090,7 +1102,8 @@ \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 +1113,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(val)); \} else \{ destroy_at(addressof(unex)); has_val = true; \} return *construct_at(addressof(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(val)); \} else \{ destroy_at(addressof(unex)); has_val = true; \} return *construct_at(addressof(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} @@ -1151,7 +1162,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}% @@ -1312,7 +1323,8 @@ \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 +1339,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,7 +1356,7 @@ \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} @@ -1362,7 +1375,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} @@ -1383,8 +1397,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} @@ -1403,8 +1419,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} @@ -1423,8 +1441,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} @@ -1443,8 +1463,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} @@ -1463,8 +1485,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} @@ -1479,8 +1503,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} @@ -1495,8 +1521,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} @@ -1520,8 +1548,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} @@ -1548,7 +1578,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 +1597,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 +1612,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 +1628,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..43d6d12 100644 --- a/papers/wording/fragments/expected.ref.tex +++ b/papers/wording/fragments/expected.ref.tex @@ -49,7 +49,8 @@ requires(!is_same_v, in_place_t> && !is_same_v, expected> && !@\exposidnc{is-unexpected-specialization}@>::value && - is_constructible_v && !reference_constructs_from_temporary_v) + is_constructible_v && + !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v) expected(U&& u) noexcept(is_nothrow_constructible_v); @@ -57,8 +58,8 @@ 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"); + BEMAN_EXPECTED_DELETE_MSG("expected: argument would bind a temporary " + "that dangles; pass an lvalue reference"); // Converting constructor from expected (copy) — value-E path template @@ -71,7 +72,8 @@ // Converting constructor from expected (move) — value-E path template requires(!is_reference_v && is_constructible_v && - is_constructible_v && !reference_constructs_from_temporary_v) + is_constructible_v && + !reference_constructs_from_temporary_v) constexpr explicit(!is_convertible_v || !is_convertible_v) expected(expected&& rhs); @@ -98,14 +100,15 @@ 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. + // 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 && @@ -113,8 +116,8 @@ 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. + // 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( @@ -139,7 +142,8 @@ BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " "temporary that dangles; pass an lvalue reference"); - // Deleted catch-all: reference E, argument neither constructible nor a dangling case + // Deleted catch-all: reference E, argument neither constructible nor a dangling + // case template requires(is_reference_v && !is_constructible_v && !@\exposidnc{unexpect-dangles-v}@) @@ -148,14 +152,16 @@ // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) + 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"); + BEMAN_EXPECTED_DELETE_MSG( + "expected: initializer-list error construction cannot bind a " + "reference; pass an lvalue reference"); // ------------------------------------------------------------------------- // Destructor @@ -204,7 +210,8 @@ template requires(!is_same_v, expected> && !@\exposidnc{is-unexpected-specialization}@>::value && - is_constructible_v && !reference_constructs_from_temporary_v) + is_constructible_v && + !reference_constructs_from_temporary_v) constexpr expected& operator=(U&& u); // Assignment from unexpected — value-E path @@ -217,8 +224,8 @@ requires(!is_reference_v && is_constructible_v && is_assignable_v) constexpr expected& operator=(unexpected&& e); - // Rebinding assignment for reference E from reference G — binds unex_ to the external - // referent. + // 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) @@ -229,23 +236,24 @@ !reference_constructs_from_temporary_v) constexpr expected& operator=(unexpected&& e); - // Deleted for reference E with value G: would rebind E& to unexpected's temporary - // storage. + // 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"); + "expected: cannot assign from unexpected; the value would dangle " + "— use unexpected"); 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"); + "expected: cannot assign from unexpected; the value would dangle " + "— use unexpected"); // emplace — rebind the reference template - requires(is_constructible_v && !reference_constructs_from_temporary_v) + requires(is_constructible_v && + !reference_constructs_from_temporary_v) constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v); // ------------------------------------------------------------------------- @@ -285,8 +293,8 @@ // 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. + // 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>>) @@ -364,15 +372,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. \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 \tcode{val} points to the referenced object, which is not owned by the \tcode{expected} object. Otherwise, the error is \tcode{unex.error()}. \rSec3[expected.ref.cons]{Constructors} @@ -384,7 +390,7 @@ \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}% @@ -451,30 +457,30 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(in_place_t, Args&&...); +template + constexpr expected(in_place_t, Args&&...); \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 \tcode{val} with \tcode{addressof(r)}. \pnum \ensures @@ -483,33 +489,32 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(U&&); +template + constexpr expected(U&&); \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 @@ -519,17 +524,15 @@ \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 @@ -543,15 +546,15 @@ \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 @@ -565,9 +568,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} @@ -590,7 +593,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -600,12 +604,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} @@ -624,7 +629,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -634,19 +640,19 @@ \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 @@ -664,7 +670,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -739,21 +745,21 @@ \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 @@ -793,17 +799,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 \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. \pnum \returns @@ -812,14 +819,16 @@ \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 @@ -832,8 +841,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} @@ -856,7 +867,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -872,17 +884,17 @@ \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 \tcode{unex} first. Sets \tcode{val} to \tcode{addressof(r)} and \tcode{has_val} to \tcode{true}. \pnum \returns @@ -894,8 +906,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} @@ -909,7 +920,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}% @@ -945,7 +956,7 @@ \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}% @@ -964,7 +975,7 @@ \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}% @@ -1048,7 +1059,8 @@ \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,7 +1070,7 @@ \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 @@ -1068,7 +1080,7 @@ \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 +1095,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 +1113,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 +1126,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), *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,23 +1152,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), *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), *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 @@ -1160,14 +1179,16 @@ \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 @@ -1176,8 +1197,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} @@ -1187,13 +1210,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), *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 +1228,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), *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 +1251,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(*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 +1274,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(*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 +1282,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 +1305,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 +1320,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 +1336,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..e8ad740 100644 --- a/papers/wording/fragments/expected.unexpected.tex +++ b/papers/wording/fragments/expected.unexpected.tex @@ -14,7 +14,8 @@ template requires(!is_same_v, unexpected> && - !is_same_v, in_place_t> && is_constructible_v) + !is_same_v, in_place_t> && + is_constructible_v) constexpr explicit unexpected(Err&& e) noexcept(is_nothrow_constructible_v); template @@ -42,7 +43,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))) + friend constexpr void swap(unexpected& x, + unexpected& y) noexcept(noexcept(x.swap(y))) requires is_swappable_v; private: @@ -51,7 +53,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 +60,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} @@ -90,8 +90,7 @@ \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} @@ -111,16 +110,14 @@ \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 @@ -136,6 +133,7 @@ \indexlibrarymember{error}{unexpected}% \begin{itemdecl} constexpr const E& error() const& noexcept; +constexpr E& error() & noexcept; \end{itemdecl} \begin{itemdescr} @@ -144,14 +142,10 @@ \tcode{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} @@ -160,11 +154,6 @@ \tcode{std::move(unex)}. \end{itemdescr} -\indexlibrarymember{error}{unexpected}% -\begin{itemdecl} -constexpr E&& error() && noexcept; -\end{itemdecl} - \rSec3[expected.un.swap]{Swap} \indexlibrarymember{swap}{unexpected}% @@ -202,7 +191,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 +236,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 +256,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 \tcode{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 \tcode{unex} with \tcode{addressof(static_cast(std::forward(e)))}. \end{itemdescr} \indexlibrarymember{error}{unexpected}% @@ -308,7 +297,7 @@ \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}% @@ -325,7 +314,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} diff --git a/papers/wording/fragments/expected.void.tex b/papers/wording/fragments/expected.void.tex index eb981a4..47c8962 100644 --- a/papers/wording/fragments/expected.void.tex +++ b/papers/wording/fragments/expected.void.tex @@ -35,12 +35,12 @@ 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. + // 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 && @@ -69,13 +69,14 @@ 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. + // 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 && @@ -112,8 +113,8 @@ BEMAN_EXPECTED_DELETE_MSG("expected: unexpect argument would bind a " "temporary that dangles; pass an lvalue reference"); - // Deleted catch-all: reference E, argument neither constructible nor a dangling case - // (e.g. binding a non-const E& from a const lvalue). + // 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}@) @@ -122,7 +123,8 @@ // In-place constructor for error with initializer_list template - requires(!is_reference_v && is_constructible_v&, Args...>) + requires(!is_reference_v && + is_constructible_v&, Args...>) constexpr explicit expected(unexpect_t, initializer_list il, Args&&... args); template @@ -132,16 +134,17 @@ "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. + // 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. 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 && @@ -188,8 +191,8 @@ requires(!is_reference_v && is_constructible_v && is_assignable_v) constexpr expected& operator=(unexpected&& e); - // Rebinding assignment for reference E from reference G — binds unex_ to the external - // referent. + // 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) @@ -200,19 +203,19 @@ !reference_constructs_from_temporary_v) constexpr expected& operator=(unexpected&& e); - // Deleted for reference E with value G: would bind E& to storage inside the temporary - // unexpected. + // 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"); + "expected: cannot assign from unexpected; the value would " + "dangle — use unexpected"); 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"); + "expected: cannot assign from unexpected; the value would " + "dangle — use unexpected"); constexpr void emplace() noexcept; @@ -257,9 +260,9 @@ 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). + // 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( @@ -326,7 +329,6 @@ } \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. @@ -334,7 +336,6 @@ \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} \rSec3[expected.void.cons]{Constructors} @@ -406,15 +407,15 @@ \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 @@ -432,15 +433,15 @@ \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 @@ -458,9 +459,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} @@ -483,7 +484,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(const unexpected&); +template + constexpr expected(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -493,7 +495,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 +511,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} @@ -532,7 +535,8 @@ \indexlibraryctor{expected}% \begin{itemdecl} -template constexpr expected(unexpect_t, Args&&...); +template + constexpr expected(unexpect_t, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -542,19 +546,19 @@ \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 @@ -576,7 +580,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template -constexpr expected(unexpect_t, initializer_list, Args&&...); + constexpr expected(unexpect_t, initializer_list, Args&&...); \end{itemdecl} \begin{itemdescr} @@ -592,15 +596,15 @@ \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 @@ -636,18 +640,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(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}. \pnum \returns @@ -660,18 +664,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(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)}. \pnum \returns @@ -679,19 +683,21 @@ \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 @@ -704,8 +710,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} @@ -732,7 +740,8 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} -template constexpr expected& operator=(const unexpected&); +template + constexpr expected& operator=(const unexpected&); \end{itemdecl} \begin{itemdescr} @@ -761,8 +770,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} @@ -780,7 +788,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}% @@ -889,7 +897,7 @@ \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} @@ -908,7 +916,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} @@ -927,7 +936,8 @@ \indexlibrarymember{value_or}{expected}% \begin{itemdecl} -template constexpr void value_or(U&&) const; +template + constexpr void value_or(U&&) const; \end{itemdecl} \begin{itemdescr} @@ -944,8 +954,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 +976,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 +998,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 +1016,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 +1034,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 +1056,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 +1078,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} @@ -1072,8 +1096,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} @@ -1091,7 +1117,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 +1137,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 +1147,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} From b796f6c694e3f303c05960d656ce36019cc42cb7 Mon Sep 17 00:00:00 2001 From: Steve Downey Date: Mon, 16 Nov 2026 20:24:36 -0500 Subject: [PATCH 3/3] Regenerate the wording with specgen 0.41.1 No header changed. specgen 0.41.1 (9d1689d) renders the same docblocks differently from 0.23.0 in four ways: - A plain comment in a class body is no longer carried into the synopsis. 194 comment lines go, the banner comments among them, since none is written as a `// \ref{...}` group header. - A requires-clause that the item declaration states as Constraints is dropped from the synopsis too. It stays on a deleted member that has no item of its own. - A deleted member reads `= delete;`. In the synopses that replaces BEMAN_EXPECTED_DELETE_MSG and its message, 25 times; in the item declarations, which showed no tail, it is added 16 times. - An exposition-only name in an authored code span renders as one: `unex`, `val` and `error-value-type` are \exposid where they were plain code. Apart from those names the prose is the same, token for token. --- papers/wording/expected.tex | 1185 ++++------------- papers/wording/fragments/expected.bad.tex | 4 +- .../wording/fragments/expected.expected.tex | 488 ++----- papers/wording/fragments/expected.ref.tex | 361 ++--- .../wording/fragments/expected.unexpected.tex | 36 +- papers/wording/fragments/expected.void.tex | 298 +---- 6 files changed, 579 insertions(+), 1793 deletions(-) diff --git a/papers/wording/expected.tex b/papers/wording/expected.tex index 0afdf9c..dfa1a88 100644 --- a/papers/wording/expected.tex +++ b/papers/wording/expected.tex @@ -25,25 +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&, @@ -63,8 +56,7 @@ 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; + unexpected& y) noexcept(noexcept(x.swap(y))); private: E @\exposidnc{unex}@; // exposition only @@ -99,11 +91,11 @@ \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}% @@ -119,11 +111,11 @@ \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}% @@ -140,11 +132,11 @@ \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} @@ -158,7 +150,7 @@ \begin{itemdescr} \pnum \returns -\tcode{unex}. +\exposid{unex}. \end{itemdescr} \indexlibrarymember{error}{unexpected}% @@ -170,7 +162,7 @@ \begin{itemdescr} \pnum \returns -\tcode{std::move(unex)}. +\tcode{std::move(\exposid{unex})}. \end{itemdescr} \rSec3[expected.un.swap]{Swap} @@ -187,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}% @@ -281,7 +273,7 @@ \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 @@ -301,7 +293,7 @@ \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}% @@ -312,7 +304,7 @@ \begin{itemdescr} \pnum \returns -\tcode{*unex}. +\tcode{*\exposid{unex}}. \pnum \remarks @@ -327,7 +319,7 @@ \begin{itemdescr} \pnum \effects -Exchanges \tcode{unex} and \tcode{other.unex}. +Exchanges \exposid{unex} and \tcode{other.\exposid{unex}}. \end{itemdescr} \indexlibraryglobal{operator==}% @@ -444,7 +436,7 @@ \begin{itemdescr} \pnum \returns -\tcode{std::move(unex)}. +\tcode{std::move(\exposid{unex})}. \end{itemdescr} \indexlibrarymember{error}{bad_expected_access}% @@ -455,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} @@ -500,316 +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)); - - // 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. + is_nothrow_copy_constructible_v && is_nothrow_copy_constructible_v); + 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; 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; @@ -837,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 @@ -933,7 +683,7 @@ \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. +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} @@ -949,7 +699,7 @@ \pnum \effects -Value-initializes \tcode{val}. +Value-initializes \exposid{val}. \pnum \ensures @@ -957,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}% @@ -968,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 @@ -992,7 +742,7 @@ \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 @@ -1000,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 @@ -1015,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 @@ -1038,7 +788,7 @@ \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 @@ -1046,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 @@ -1069,7 +819,7 @@ \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 @@ -1077,7 +827,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}. \end{itemdescr} \indexlibraryctor{expected}% @@ -1095,7 +845,7 @@ \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 @@ -1103,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 @@ -1123,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 @@ -1131,7 +881,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}% @@ -1149,7 +899,7 @@ \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 @@ -1157,7 +907,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% @@ -1175,7 +925,7 @@ \pnum \effects -Initializes \tcode{unex} with \tcode{e.error()}. +Initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -1189,7 +939,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(const unexpected&); + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -1215,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 @@ -1223,7 +973,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}% @@ -1239,7 +989,7 @@ \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 @@ -1247,7 +997,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}% @@ -1263,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 @@ -1271,13 +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&&...); + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -1303,7 +1053,7 @@ \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 @@ -1311,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 @@ -1321,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} @@ -1348,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 @@ -1367,7 +1117,7 @@ \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} @@ -1423,7 +1173,7 @@ \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 @@ -1485,7 +1235,7 @@ \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 @@ -1509,7 +1259,7 @@ \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 @@ -1531,7 +1281,7 @@ \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 @@ -1553,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 @@ -1571,7 +1321,7 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} template - constexpr expected& operator=(const unexpected&); + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -1581,7 +1331,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}% @@ -1597,7 +1347,7 @@ \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}% @@ -1613,7 +1363,7 @@ \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} @@ -1638,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 @@ -1685,7 +1435,7 @@ \pnum \returns -\tcode{addressof(val)}. +\tcode{addressof(\exposid{val})}. \end{itemdescr} \indexlibrarymember{operator*}{expected}% @@ -1701,7 +1451,7 @@ \pnum \returns -\tcode{val}. +\exposid{val}. \end{itemdescr} \indexlibrarymember{operator*}{expected}% @@ -1717,7 +1467,7 @@ \pnum \returns -\tcode{std::move(val)}. +\tcode{std::move(\exposid{val})}. \end{itemdescr} \indexlibrarymember{operator bool}{expected}% @@ -1746,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 @@ -1766,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 @@ -1786,7 +1536,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -1802,7 +1552,7 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{value_or}{expected}% @@ -1846,11 +1596,11 @@ \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 @@ -1866,11 +1616,11 @@ \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 @@ -1894,11 +1644,11 @@ \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}% @@ -1916,11 +1666,11 @@ \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}% @@ -1934,7 +1684,7 @@ \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1942,7 +1692,7 @@ \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}% @@ -1956,7 +1706,7 @@ \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1964,7 +1714,7 @@ \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}% @@ -1982,7 +1732,7 @@ \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}% @@ -2000,7 +1750,7 @@ \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}% @@ -2014,7 +1764,7 @@ \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -2027,7 +1777,7 @@ \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}% @@ -2041,7 +1791,7 @@ \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -2054,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} @@ -2133,224 +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; 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); 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; @@ -2360,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 @@ -2452,7 +2032,7 @@ \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()}. +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} @@ -2479,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 @@ -2487,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 @@ -2506,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 @@ -2514,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 @@ -2536,7 +2116,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 @@ -2544,7 +2124,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% @@ -2562,7 +2142,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{e.error()}. +Direct-non-list-initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -2570,7 +2150,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% @@ -2588,7 +2168,7 @@ \pnum \effects -Initializes \tcode{unex} with \tcode{e.error()}. +Initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -2602,7 +2182,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(const unexpected&); + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -2639,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 @@ -2647,13 +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&&...); + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -2679,7 +2259,7 @@ \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 @@ -2687,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 @@ -2697,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} @@ -2725,7 +2305,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 @@ -2746,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 @@ -2768,7 +2348,7 @@ \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 @@ -2792,7 +2372,7 @@ \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 @@ -2818,7 +2398,7 @@ \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 @@ -2840,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 @@ -2858,7 +2438,7 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} template - constexpr expected& operator=(const unexpected&); + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -2868,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}% @@ -2879,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} @@ -2897,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 @@ -2992,7 +2572,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -3008,7 +2588,7 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{error_or}{expected}% @@ -3024,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 @@ -3044,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 @@ -3054,7 +2634,7 @@ \indexlibrarymember{value_or}{expected}% \begin{itemdecl} template - constexpr void value_or(U&&) const; + constexpr void value_or(U&&) const = delete; \end{itemdecl} \begin{itemdescr} @@ -3208,7 +2788,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), 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}% @@ -3226,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} @@ -3285,261 +2865,113 @@ template using rebind = expected; - // ------------------------------------------------------------------------- - // Constructors - // ------------------------------------------------------------------------- - - expected() = BEMAN_EXPECTED_DELETE_MSG( - "expected: no default constructor; T& cannot be null"); + expected() = delete; - // 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; 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"); - - // ------------------------------------------------------------------------- - // Destructor - // ------------------------------------------------------------------------- - - constexpr ~expected() - requires is_trivially_destructible_v - = default; - - constexpr ~expected() - requires(!is_trivially_destructible_v); - - // ------------------------------------------------------------------------- - // Assignment (rebind semantics) - // ------------------------------------------------------------------------- - - // 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; - - // 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) - 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) + 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) - 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; @@ -3550,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 @@ -3647,13 +3040,13 @@ \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()}. +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} @@ -3670,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 @@ -3694,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 @@ -3713,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 @@ -3727,7 +3120,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(in_place_t, Args&&...); + constexpr expected(in_place_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -3749,7 +3142,7 @@ \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 @@ -3759,7 +3152,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(U&&); + constexpr expected(U&&) = delete; \end{itemdecl} \begin{itemdescr} @@ -3787,7 +3180,7 @@ \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}% @@ -3805,7 +3198,7 @@ \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 @@ -3827,7 +3220,7 @@ \pnum \effects -Initializes \tcode{unex} with the error of \tcode{e}. +Initializes \exposid{unex} with the error of \tcode{e}. \pnum \ensures @@ -3849,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 @@ -3863,7 +3256,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(const unexpected&); + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -3889,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 @@ -3899,7 +3292,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(unexpect_t, Args&&...); + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -3925,7 +3318,7 @@ \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 @@ -3939,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} @@ -3985,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 @@ -4006,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 @@ -4032,7 +3425,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 @@ -4055,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 @@ -4079,7 +3472,7 @@ \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 @@ -4101,7 +3494,7 @@ \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 @@ -4123,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 @@ -4137,7 +3530,7 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} template - constexpr expected& operator=(const unexpected&); + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -4147,7 +3540,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}% @@ -4163,11 +3556,11 @@ \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} @@ -4185,7 +3578,7 @@ \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 @@ -4221,7 +3614,7 @@ \pnum \returns -\tcode{val}. +\exposid{val}. \pnum \remarks @@ -4240,7 +3633,7 @@ \pnum \returns -\tcode{*val}. +\tcode{*\exposid{val}}. \pnum \remarks @@ -4272,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 @@ -4287,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 @@ -4307,7 +3700,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -4323,7 +3716,7 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{value_or}{expected}% @@ -4343,7 +3736,7 @@ \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}% @@ -4399,7 +3792,7 @@ \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 @@ -4425,7 +3818,7 @@ \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}% @@ -4443,7 +3836,7 @@ \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}% @@ -4461,7 +3854,7 @@ \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}% @@ -4479,7 +3872,7 @@ \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}% @@ -4497,7 +3890,7 @@ \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}% @@ -4520,7 +3913,7 @@ \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}% @@ -4543,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} diff --git a/papers/wording/fragments/expected.bad.tex b/papers/wording/fragments/expected.bad.tex index d146504..0adc951 100644 --- a/papers/wording/fragments/expected.bad.tex +++ b/papers/wording/fragments/expected.bad.tex @@ -85,7 +85,7 @@ \begin{itemdescr} \pnum \returns -\tcode{std::move(unex)}. +\tcode{std::move(\exposid{unex})}. \end{itemdescr} \indexlibrarymember{error}{bad_expected_access}% @@ -96,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 9f10838..10b88f6 100644 --- a/papers/wording/fragments/expected.expected.tex +++ b/papers/wording/fragments/expected.expected.tex @@ -16,316 +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)); - - // 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. + is_nothrow_copy_constructible_v && is_nothrow_copy_constructible_v); + 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; 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; @@ -353,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 @@ -449,7 +207,7 @@ \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. +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} @@ -465,7 +223,7 @@ \pnum \effects -Value-initializes \tcode{val}. +Value-initializes \exposid{val}. \pnum \ensures @@ -473,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}% @@ -484,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 @@ -508,7 +266,7 @@ \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 @@ -516,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 @@ -531,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 @@ -554,7 +312,7 @@ \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 @@ -562,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 @@ -585,7 +343,7 @@ \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 @@ -593,7 +351,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}. \end{itemdescr} \indexlibraryctor{expected}% @@ -611,7 +369,7 @@ \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 @@ -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,7 +405,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}% @@ -665,7 +423,7 @@ \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,7 +431,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% @@ -691,7 +449,7 @@ \pnum \effects -Initializes \tcode{unex} with \tcode{e.error()}. +Initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -705,7 +463,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(const unexpected&); + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -731,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 @@ -739,7 +497,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}% @@ -755,7 +513,7 @@ \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 @@ -763,7 +521,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}% @@ -779,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 @@ -787,13 +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&&...); + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -819,7 +577,7 @@ \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 @@ -827,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 @@ -837,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} @@ -864,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 @@ -883,7 +641,7 @@ \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} @@ -939,7 +697,7 @@ \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 @@ -1001,7 +759,7 @@ \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 @@ -1025,7 +783,7 @@ \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 @@ -1047,7 +805,7 @@ \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 @@ -1069,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 @@ -1087,7 +845,7 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} template - constexpr expected& operator=(const unexpected&); + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -1097,7 +855,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}% @@ -1113,7 +871,7 @@ \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}% @@ -1129,7 +887,7 @@ \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} @@ -1154,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 @@ -1201,7 +959,7 @@ \pnum \returns -\tcode{addressof(val)}. +\tcode{addressof(\exposid{val})}. \end{itemdescr} \indexlibrarymember{operator*}{expected}% @@ -1217,7 +975,7 @@ \pnum \returns -\tcode{val}. +\exposid{val}. \end{itemdescr} \indexlibrarymember{operator*}{expected}% @@ -1233,7 +991,7 @@ \pnum \returns -\tcode{std::move(val)}. +\tcode{std::move(\exposid{val})}. \end{itemdescr} \indexlibrarymember{operator bool}{expected}% @@ -1262,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 @@ -1282,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 @@ -1302,7 +1060,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -1318,7 +1076,7 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{value_or}{expected}% @@ -1362,11 +1120,11 @@ \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 @@ -1382,11 +1140,11 @@ \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 @@ -1410,11 +1168,11 @@ \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}% @@ -1432,11 +1190,11 @@ \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}% @@ -1450,7 +1208,7 @@ \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1458,7 +1216,7 @@ \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}% @@ -1472,7 +1230,7 @@ \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1480,7 +1238,7 @@ \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}% @@ -1498,7 +1256,7 @@ \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}% @@ -1516,7 +1274,7 @@ \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}% @@ -1530,7 +1288,7 @@ \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1543,7 +1301,7 @@ \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}% @@ -1557,7 +1315,7 @@ \begin{itemdescr} \pnum \constraints -\tcode{is_constructible_v} is \tcode{true}. +\tcode{is_constructible_v} is \tcode{true}. \pnum \mandates @@ -1570,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} diff --git a/papers/wording/fragments/expected.ref.tex b/papers/wording/fragments/expected.ref.tex index 43d6d12..0b6768d 100644 --- a/papers/wording/fragments/expected.ref.tex +++ b/papers/wording/fragments/expected.ref.tex @@ -16,261 +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; 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"); - - // ------------------------------------------------------------------------- - // Destructor - // ------------------------------------------------------------------------- - - constexpr ~expected() - requires is_trivially_destructible_v - = default; - - constexpr ~expected() - requires(!is_trivially_destructible_v); - - // ------------------------------------------------------------------------- - // Assignment (rebind semantics) - // ------------------------------------------------------------------------- - - // 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; - - // 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) - 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) + 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) - 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; @@ -281,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 @@ -378,13 +191,13 @@ \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()}. +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} @@ -401,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 @@ -425,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 @@ -444,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 @@ -458,7 +271,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(in_place_t, Args&&...); + constexpr expected(in_place_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -480,7 +293,7 @@ \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 @@ -490,7 +303,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(U&&); + constexpr expected(U&&) = delete; \end{itemdecl} \begin{itemdescr} @@ -518,7 +331,7 @@ \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}% @@ -536,7 +349,7 @@ \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 @@ -558,7 +371,7 @@ \pnum \effects -Initializes \tcode{unex} with the error of \tcode{e}. +Initializes \exposid{unex} with the error of \tcode{e}. \pnum \ensures @@ -580,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 @@ -594,7 +407,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(const unexpected&); + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -620,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 @@ -630,7 +443,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(unexpect_t, Args&&...); + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -656,7 +469,7 @@ \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 @@ -670,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} @@ -716,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 @@ -737,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 @@ -763,7 +576,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 @@ -786,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 @@ -810,7 +623,7 @@ \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 @@ -832,7 +645,7 @@ \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 @@ -854,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 @@ -868,7 +681,7 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} template - constexpr expected& operator=(const unexpected&); + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -878,7 +691,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}% @@ -894,11 +707,11 @@ \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} @@ -916,7 +729,7 @@ \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 @@ -952,7 +765,7 @@ \pnum \returns -\tcode{val}. +\exposid{val}. \pnum \remarks @@ -971,7 +784,7 @@ \pnum \returns -\tcode{*val}. +\tcode{*\exposid{val}}. \pnum \remarks @@ -1003,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 @@ -1018,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 @@ -1038,7 +851,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -1054,7 +867,7 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{value_or}{expected}% @@ -1074,7 +887,7 @@ \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}% @@ -1130,7 +943,7 @@ \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 @@ -1156,7 +969,7 @@ \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}% @@ -1174,7 +987,7 @@ \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}% @@ -1192,7 +1005,7 @@ \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}% @@ -1210,7 +1023,7 @@ \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}% @@ -1228,7 +1041,7 @@ \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}% @@ -1251,7 +1064,7 @@ \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}% @@ -1274,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} diff --git a/papers/wording/fragments/expected.unexpected.tex b/papers/wording/fragments/expected.unexpected.tex index e8ad740..cdeeaf7 100644 --- a/papers/wording/fragments/expected.unexpected.tex +++ b/papers/wording/fragments/expected.unexpected.tex @@ -6,25 +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&, @@ -44,8 +37,7 @@ 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; + unexpected& y) noexcept(noexcept(x.swap(y))); private: E @\exposidnc{unex}@; // exposition only @@ -80,11 +72,11 @@ \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}% @@ -100,11 +92,11 @@ \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}% @@ -121,11 +113,11 @@ \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} @@ -139,7 +131,7 @@ \begin{itemdescr} \pnum \returns -\tcode{unex}. +\exposid{unex}. \end{itemdescr} \indexlibrarymember{error}{unexpected}% @@ -151,7 +143,7 @@ \begin{itemdescr} \pnum \returns -\tcode{std::move(unex)}. +\tcode{std::move(\exposid{unex})}. \end{itemdescr} \rSec3[expected.un.swap]{Swap} @@ -168,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}% @@ -262,7 +254,7 @@ \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 @@ -282,7 +274,7 @@ \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}% @@ -293,7 +285,7 @@ \begin{itemdescr} \pnum \returns -\tcode{*unex}. +\tcode{*\exposid{unex}}. \pnum \remarks @@ -308,7 +300,7 @@ \begin{itemdescr} \pnum \effects -Exchanges \tcode{unex} and \tcode{other.unex}. +Exchanges \exposid{unex} and \tcode{other.\exposid{unex}}. \end{itemdescr} \indexlibraryglobal{operator==}% diff --git a/papers/wording/fragments/expected.void.tex b/papers/wording/fragments/expected.void.tex index 47c8962..d9f8ed4 100644 --- a/papers/wording/fragments/expected.void.tex +++ b/papers/wording/fragments/expected.void.tex @@ -16,224 +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); - - // 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; 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); 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)); + is_nothrow_copy_constructible_v && is_nothrow_copy_assignable_v); - // Move assignment (trivial path) - - // 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; @@ -243,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 @@ -335,7 +165,7 @@ \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()}. +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} @@ -362,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 @@ -370,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 @@ -389,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 @@ -397,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 @@ -419,7 +249,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 @@ -427,7 +257,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% @@ -445,7 +275,7 @@ \pnum \effects -Direct-non-list-initializes \tcode{unex} with \tcode{e.error()}. +Direct-non-list-initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -453,7 +283,7 @@ \pnum \throws -Any exception thrown by the initialization of \tcode{unex}. +Any exception thrown by the initialization of \exposid{unex}. \end{itemdescr} \indexlibraryctor{expected}% @@ -471,7 +301,7 @@ \pnum \effects -Initializes \tcode{unex} with \tcode{e.error()}. +Initializes \exposid{unex} with \tcode{e.error()}. \pnum \ensures @@ -485,7 +315,7 @@ \indexlibraryctor{expected}% \begin{itemdecl} template - constexpr expected(const unexpected&); + constexpr expected(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -522,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 @@ -530,13 +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&&...); + constexpr expected(unexpect_t, Args&&...) = delete; \end{itemdecl} \begin{itemdescr} @@ -562,7 +392,7 @@ \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 @@ -570,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 @@ -580,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} @@ -608,7 +438,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 @@ -629,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 @@ -651,7 +481,7 @@ \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 @@ -675,7 +505,7 @@ \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 @@ -701,7 +531,7 @@ \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 @@ -723,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 @@ -741,7 +571,7 @@ \indexlibrarymember{operator=}{expected}% \begin{itemdecl} template - constexpr expected& operator=(const unexpected&); + constexpr expected& operator=(const unexpected&) = delete; \end{itemdecl} \begin{itemdescr} @@ -751,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}% @@ -762,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} @@ -780,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 @@ -875,7 +705,7 @@ \pnum \returns -\tcode{unex.error()}. +\tcode{\exposid{unex}.error()}. \end{itemdescr} \indexlibrarymember{error}{expected}% @@ -891,7 +721,7 @@ \pnum \returns -\tcode{std::move(unex).error()}. +\tcode{std::move(\exposid{unex}).error()}. \end{itemdescr} \indexlibrarymember{error_or}{expected}% @@ -907,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 @@ -927,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 @@ -937,7 +767,7 @@ \indexlibrarymember{value_or}{expected}% \begin{itemdecl} template - constexpr void value_or(U&&) const; + constexpr void value_or(U&&) const = delete; \end{itemdecl} \begin{itemdescr} @@ -1091,7 +921,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), 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}% @@ -1109,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}