Issue 4154: The Mandates for std::packaged_task's constructor from a callable entity should consider decaying (original) (raw)


This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of WP status.

4154. The Mandates for std::packaged_task's constructor from a callable entity should consider decaying

Section: 32.10.10.2 [futures.task.members] Status: WP Submitter: Jiang An Opened: 2024-09-18 Last modified: 2024-11-28

Priority: 3

View all other issues in [futures.task.members].

View all issues with WP status.

Discussion:

Currently, 32.10.10.2 [futures.task.members]/3 states:

Mandates:is_invocable_r_v<R, F&, ArgTypes...> is true.

where F& can be a reference to a cv-qualified function object type.

However, in mainstream implementations (libc++, libstdc++, and MSVC STL), the stored task object always has a cv-unqualified type, and thus the cv-qualification is unrecognizable in operator().

Since 22.10.17.3.2 [func.wrap.func.con] uses a decayed type, perhaps we should also so specify for std::packaged_task.

[2024-10-02; Reflector poll]

Set priority to 3 after reflector poll.

"Fix preconditions, f doesn't need to be invocable, we only invoke the copy."

Previous resolution [SUPERSEDED]:

This wording is relative to N4988.

  1. Modify 32.10.10.2 [futures.task.members] as indicated:

    -3- Mandates:is_invocable_r_v<R, ~~F~~decay_t<F>&, ArgTypes...>is true.

    [...]

    -5- Effects: Constructs a new packaged_task object with a shared state and initializes the object's stored taskof type decay_t<F>with std::forward<F>(f).

[2024-10-02; Jonathan provides improved wording]

Drop preconditions as suggested on reflector.

[2024-10-02; LWG telecon]

Clarify that "of type decay_t<F>" is supposed to be specifying the type of the stored task.

[2024-10-09; LWG telecon: Move to Ready]

[Wrocław 2024-11-23; Status changed: Voting → WP.]

Proposed resolution:

This wording is relative to N4988.

  1. Modify 32.10.10.2 [futures.task.members] as indicated:
    template<class F>  
     explicit packaged_task(F&& f);  

    -2- Constraints:remove_cvref_t<F> is not the same type aspackaged_task<R(ArgTypes...)>.

    -3- Mandates:is_invocable_r_v<R, ~~F~~decay_t<F>&, ArgTypes...>is true.

    -4- Preconditions: Invoking a copy of f behaves the same as invoking f.

    -5- Effects: Constructs a new packaged_task object witha stored task of type decay_t<F> anda shared state. Initializes and initializesthe object's stored task with std::forward<F>(f).