Title
function/packaged_task deduction guides and deducing this
Status
c++23
Section
[func.wrap.func.con][futures.task.members]
Submitter
Barry Revzin

Created on 2021-10-09.00:00:00 last changed 4 months ago

Messages

Date: 2022-07-25.20:32:58

Proposed resolution:

This wording is relative to N4892.

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

    template<class F> function(F) -> function<see below>;
    

    -16- Constraints: &F::operator() is well-formed when treated as an unevaluated operand and decltype(&F::operator()) is either of the form R(G::*)(A...) cv &opt noexceptopt or of the form R(*)(G, A...) noexceptopt for a class type G.

    -17- Remarks: The deduced type is function<R(A...)>.

  2. Modify [futures.task.members] as indicated:

    template<class F> packaged_task(F) -> packaged_task<see below>;
    

    -7- Constraints: &F::operator() is well-formed when treated as an unevaluated operand and decltype(&F::operator()) is either of the form R(G::*)(A...) cv &opt noexceptopt or of the form R(*)(G, A...) noexceptopt for a class type G.

    -8- Remarks: The deduced type is packaged_task<R(A...)>.

Date: 2022-07-25.00:00:00

[ 2022-07-25 Approved at July 2022 virtual plenary. Status changed: Ready → WP. ]

Date: 2022-07-15.00:00:00

[ 2022-07-15; LWG telecon: move to Ready ]

Date: 2022-07-15.00:00:00

[ 2022-07-01; Reflector poll ]

Set status to Tentatively Ready after nine votes in favour during reflector poll.

Date: 2021-10-15.00:00:00

[ 2021-10-17; Improved wording based on Tim Song's suggestion ]

Date: 2021-10-15.00:00:00

[ 2021-10-14; Reflector poll ]

Set priority to 2 after reflector poll.

Previous resolution [SUPERSEDED]:

This wording is relative to N4892.

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

    template<class F> function(F) -> function<see below>;
    

    -16- Constraints: &F::operator() is well-formed when treated as an unevaluated operand and decltype(&F::operator()) is either of the form R(G::*)(A...) cv &opt noexceptopt or of the form R(*)(G cv &opt, A...) noexceptopt for a class type G.

    -17- Remarks: The deduced type is function<R(A...)>.

  2. Modify [futures.task.members] as indicated:

    template<class F> packaged_task(F) -> packaged_task<see below>;
    

    -7- Constraints: &F::operator() is well-formed when treated as an unevaluated operand and decltype(&F::operator()) is either of the form R(G::*)(A...) cv &opt noexceptopt or of the form R(*)(G cv &opt, A...) noexceptopt for a class type G.

    -8- Remarks: The deduced type is packaged_task<R(A...)>.

Date: 2021-10-09.00:00:00

With the adoption of deducing this (P0847), we can now create types whose call operator is an explicit object member function, which means that decltype(&F::operator()) could have pointer-to-function type rather than pointer-to-member-function type. This means that the deduction guides for std::function ([func.wrap.func.con]) and std::packaged_task ([futures.task.members]) will simply fail:

struct F {
  int operator()(this const F&) { return 42; }
};

std::function g = F{}; // error: decltype(&F::operator()) is not of the form R(G::*)(A...) cv &opt noexceptopt

We should update the deduction guides to keep them in line with the core language.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-07-25 20:32:58adminsetmessages: + msg12634
2022-07-25 20:32:58adminsetstatus: ready -> wp
2022-07-25 20:28:19adminsetmessages: + msg12608
2022-07-01 19:45:27adminsetmessages: + msg12540
2022-07-01 19:45:27adminsetstatus: new -> ready
2021-10-17 11:01:02adminsetmessages: + msg12174
2021-10-14 11:35:36adminsetmessages: + msg12171
2021-10-10 11:11:03adminsetmessages: + msg12106
2021-10-09 00:00:00admincreate