This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
optional<T&>::or_elseSection: 22.5.4.7 [optional.ref.monadic] Status: New Submitter: Hewill Kang Opened: 2025-09-07 Last modified: 2025-10-16
Priority: 4
View other active issues in [optional.ref.monadic].
View all other issues in [optional.ref.monadic].
View all issues with New status.
Discussion:
optional<T&>::or_else currently returns *val when it has a value,
which calls the optional(U&&) constructor which in turn calls
convert-ref-init-val which in turn calls addressof.
optional<T&>'s
default copy constructor to just copy a pointer.
[2025-10-16; Reflector poll]
Set priority to 4 after reflector poll.
"NAD, no observable difference." "Still simpler to not have to reason about whether it matters, let's do it."
Proposed resolution:
This wording is relative to N5014.
Modify 22.5.4.7 [optional.ref.monadic] as indicated:
template<class F> constexpr optional or_else(F&& f) const;-7- Constraints:
-8- Mandates:Fmodelsinvocable.is_same_v<remove_cvref_t<invoke_result_t<F>>, optional>istrue. -9- Effects: Equivalent to:if (has_value()) { return *thisval; } else { return std::forward<F>(f)(); }