|
2988 | 2988 | friend constexpr bool operator==(const expected&, const unexpected<E2>&); |
2989 | 2989 |
|
2990 | 2990 | private: |
2991 | | - bool @\exposid{has_val}@; // \expos |
| 2991 | + bool @\exposid{has_val}@; // \expos |
2992 | 2992 | union { |
2993 | | - T* @\exposid{val}@; // \expos |
2994 | | - E @\exposid{unex}@; // \expos |
| 2993 | + T* @\exposid{val}@; // \expos |
| 2994 | + unexpected<E> @\exposid{unex}@; // \expos |
2995 | 2995 | }; |
2996 | 2996 | }; |
2997 | 2997 | \end{codeblock} |
2998 | 2998 |
|
2999 | 2999 | \pnum |
3000 | | -Any object of type \tcode{expected<T\&, E>} either |
3001 | | -represents a reference to an object of type \tcode{T}, or |
3002 | | -contains a value of type \tcode{E} nested within\iref{intro.object} it. |
3003 | | -Member \exposid{has_val} indicates whether the \tcode{expected<T\&, E>} object |
3004 | | -represents a reference. |
3005 | | -When an \tcode{expected<T\&, E>} object represents a reference, |
3006 | | -member \exposid{val} points to the referenced object, |
3007 | | -which is not owned by the \tcode{expected} object. |
| 3000 | +An object of type \tcode{expected<T\&, E>} either represents a reference to an |
| 3001 | +object of type \tcode{T}, or holds an error. |
| 3002 | +Member \exposid{has_val} indicates whether the object represents a reference. |
| 3003 | +When it represents a reference, member \exposid{val} points to the referenced |
| 3004 | +object, which is not owned by the \tcode{expected} object. |
| 3005 | +Otherwise, the error is \tcode{\exposid{unex}.error()}. |
| 3006 | + |
| 3007 | +\pnum |
| 3008 | +The error is held as an \tcode{unexpected<E>}, and not as an \tcode{E}, so that |
| 3009 | +\tcode{E} can be an lvalue reference type: an \tcode{E\&} cannot be a union |
| 3010 | +member, whereas \tcode{unexpected<E\&>} holds a pointer to an external |
| 3011 | +object\iref{expected.un.ref}. |
3008 | 3012 |
|
3009 | 3013 | \pnum |
3010 | 3014 | A program that instantiates the definition of |
|
3030 | 3034 | \effects |
3031 | 3035 | If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with |
3032 | 3036 | \tcode{rhs.\exposid{val}}, so that \tcode{*this} and \tcode{rhs} refer to the |
3033 | | -same object; otherwise, initializes \exposid{unex} with the error of |
3034 | | -\tcode{rhs}. |
| 3037 | +same object; otherwise, initializes \exposid{unex} with |
| 3038 | +\tcode{rhs.\exposid{unex}}. |
3035 | 3039 |
|
3036 | 3040 | \pnum |
3037 | 3041 | \ensures |
|
3162 | 3166 |
|
3163 | 3167 | \pnum |
3164 | 3168 | \effects |
3165 | | -Initializes \exposid{unex} with the given arguments. |
| 3169 | +Direct-non-list-initializes \exposid{unex} with \tcode{in_place} and |
| 3170 | +\tcode{std::forward<Args>(args)...} (respectively, \tcode{in_place}, |
| 3171 | +\tcode{il}, and \tcode{std::forward<Args>(args)...}), so that the error |
| 3172 | +\tcode{\exposid{unex}.error()} is constructed from those arguments. |
3166 | 3173 | \tcode{has_value()} is \tcode{false}. |
3167 | 3174 | \end{itemdescr} |
3168 | 3175 |
|
|
3258 | 3265 |
|
3259 | 3266 | \pnum |
3260 | 3267 | \effects |
3261 | | -Makes \tcode{*this} hold the error of \tcode{e}. When \tcode{E} is a reference |
3262 | | -type, \exposid{unex} is made to refer to the same object as \tcode{e.error()}; |
3263 | | -the previously referenced object, if any, is not modified. |
| 3268 | +Makes \tcode{*this} hold the error of \tcode{e}, reinitializing \exposid{unex} |
| 3269 | +from \tcode{e} rather than assigning through it. When \tcode{E} is a reference |
| 3270 | +type, \tcode{\exposid{unex}.error()} thereafter refers to the same object as |
| 3271 | +\tcode{e.error()}; the previously referenced object, if any, is not modified. |
3264 | 3272 |
|
3265 | 3273 | \pnum |
3266 | 3274 | \returns |
|
3402 | 3410 |
|
3403 | 3411 | \pnum |
3404 | 3412 | \returns |
3405 | | -A reference to the error, as for the primary template |
3406 | | -(\ref{expected.object.obs}). |
| 3413 | +\tcode{\exposid{unex}.error()}, with the \tcode{const} and reference |
| 3414 | +qualification of the selected overload. |
3407 | 3415 | \end{itemdescr} |
3408 | 3416 |
|
3409 | 3417 | \indexlibrarymember{value_or}{expected}% |
|
0 commit comments