Title
The constructor of std::function taking an F is missing a constraint
Status
new
Section
[func.wrap.func.con]
Submitter
Ville Voutilainen

Created on 2020-10-31.00:00:00 last changed 3 months ago

Messages

Date: 2021-01-15.21:45:23

Proposed resolution:

This wording is relative to N4868.

  1. Modify [func.wrap.func.con] as indicated:

    template<class F> function(F f);
    

    -8- Constraints: F is Lvalue-Callable ([func.wrap.func.general]) for argument types ArgTypes... and return type R, and is_copy_constructible_v<F> is true.

    -9- Preconditions: F meets the Cpp17CopyConstructible requirements.

    […]

Date: 2021-01-15.00:00:00

[ 2021-01-15; Telecon prioritization ]

Set priority to 3 following reflector and telecon discussions.

Date: 2020-11-15.00:00:00

[ 2020-11-01; Daniel comments ]

This issue has some overlap with LWG 2774.

Date: 2020-10-31.00:00:00

In P0288, any_invocable is (correctly) constraining its constructor that takes an F:

template<class F> any_invocable(F&& f);

Let VT be decay_t<F>.

Constraints:

  1. — […]

  2. is_constructible_v<VT, F> is true, and

  3. — […]

std::function doesn't do that. According to N4868, [func.wrap.func.con] p8 has a constraint for Lvalue-Callable, but not for copy-constructibility. There is a precondition in p9, but that's not enough for portable well/ill-formedness.

Since this is a constructor, and we want to give the right answer to is_constructible/constructible_from queries, we should add the relevant constraint.

History
Date User Action Args
2021-01-15 21:45:23adminsetmessages: + msg11649
2020-11-01 16:53:29adminsetmessages: + msg11525
2020-11-01 16:53:29adminsetmessages: + msg11524
2020-10-31 00:00:00admincreate