Skip to content

optional::transform mandates are too strict - need to allow references #48

Description

@steve-downey

Don't overconstrain the types that can result from transform if optional<T&> is allowed.

https://eel.is/c++draft/optional#monadic-7
Let U be remove_cv_t<invoke_result_t<F, decltype(*val)>>.

https://eel.is/c++draft/optional#monadic-8
Mandates: U is a non-array object type other than in_place_t or nullopt_t. The declaration
U u(invoke(std::forward(f), *val));
is well-formed for some invented variable u.
[Note 1: There is no requirement that U is movable ([dcl.init.general]). — end note]

However, if optional<T&> is allowed, the object type requirement is too strong -- is_object_v<U> will prohibit a reference returning function creating an optional where U is a reference.

Caught by existing test case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions