This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Tentatively Ready status.
optional<T&>::transformSection: 22.5.4.7 [optional.ref.monadic] Status: Tentatively Ready Submitter: Giuseppe D'Angelo Opened: 2025-07-15 Last modified: 2025-10-16
Priority: Not Prioritized
View other active issues in [optional.ref.monadic].
View all other issues in [optional.ref.monadic].
View all issues with Tentatively Ready status.
Discussion:
In 22.5.4.7 [optional.ref.monadic] the specification of optional<T&>::transform
is missing an additional part of the Mandates: element compared to the primary template's
transform (in 22.5.3.8 [optional.monadic] p8); that is, is missing to enforce that
the U type is a valid contained type for optional.
transform to
use this definition. The fact that the same wording has not been applied to
optional<T&>::transform as well looks like an oversight. I would
suggest to apply it.
[2025-10-16; Reflector poll]
Set status to Tentatively Ready after six votes in favour during reflector poll.
As
optional<remove_cv_t<invoke_result_t<F, T&>>>
is part of the signature (return type), we never enter the body to trigger the
Mandates, so it's already implicitly ill-formed if the result of f
is not a valid contained type. It's worth clarifying that though."
Proposed resolution:
This wording is relative to N5014.
Modify 22.5.4.7 [optional.ref.monadic] as indicated:
template<class F> constexpr optional<remove_cv_t<invoke_result_t<F, T&>>> transform(F&& f) const;-4- Let
-5- Mandates:Uberemove_cv_t<invoke_result_t<F, T&>>.Uis a valid contained type foroptional. The declarationU u(invoke(std::forward<F>(f), *val ));is well-formed for some invented variable
u.