Title
Missing Mandates: part in optional<T&>::transform
Status
wp
Section
[optional.ref.monadic]
Submitter
Giuseppe D'Angelo

Created on 2025-07-15.00:00:00 last changed 5 days ago

Messages

Date: 2025-11-11.10:48:16

Proposed resolution:

This wording is relative to N5014.

  1. Modify [optional.ref.monadic] as indicated:

    template<class F>
      constexpr optional<remove_cv_t<invoke_result_t<F, T&>>> transform(F&& f) const;
    

    -4- Let `U` be remove_cv_t<invoke_result_t<F, T&>>.

    -5- Mandates: `U` is a valid contained type for `optional`. The declaration

    U u(invoke(std::forward<F>(f), *val ));
    

    is well-formed for some invented variable `u`.

Date: 2025-11-11.10:48:16

[ Kona 2025-11-08; Status changed: Voting → WP. ]

Date: 2025-10-15.00:00:00

[ 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."

Date: 2025-07-15.00:00:00

In [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 [optional.monadic] p8); that is, is missing to enforce that the `U` type is a valid contained type for `optional`.

The definition of "valid contained type" comes from P2988R12. The paper amended the Mandates: element of the primary template's `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.

History
Date User Action Args
2025-11-11 10:48:16adminsetmessages: + msg15634
2025-11-11 10:48:16adminsetstatus: voting -> wp
2025-10-30 17:45:31adminsetstatus: ready -> voting
2025-10-16 15:51:34adminsetmessages: + msg15192
2025-10-16 15:51:34adminsetstatus: new -> ready
2025-07-26 15:45:55adminsetmessages: + msg14905
2025-07-15 00:00:00admincreate