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

3117. Missing packaged_task deduction guides

Section: 32.10.10 [futures.task] Status: C++23 Submitter: Marc Mutz Opened: 2018-06-08 Last modified: 2023-11-22

Priority: 3

View all other issues in [futures.task].

View all issues with C++23 status.

Discussion:

std::function has deduction guides, but std::packaged_task, which is otherwise very similar, does not. This is surprising to users and I can think of no reason for the former to be treated differently from the latter. I therefore propose to add deduction guides for packaged task with the same semantics as the existing ones for function.

[2018-06-23 after reflector discussion]

Priority set to 3

Previous resolution [SUPERSEDED]:

This wording is relative to N4750.

  1. Modify 32.10.10 [futures.task], class template packaged_task synopsis, as indicated:

    namespace std {
      […]
      template<class R, class... ArgTypes>
      class packaged_task<R(ArgTypes...)> {
        […]
      };
      
      template<class R, class... ArgTypes>
      packaged_task(R (*)( ArgTypes ...)) -> packaged_task<R( ArgTypes...)>;
    
      template<class F> packaged_task(F) -> packaged_task<see below>;
      
      template<class R, class... ArgTypes>
        void swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y) noexcept;
    }
    
  2. Modify 32.10.10.2 [futures.task.members] as indicated:

    template<class F>
      packaged_task(F&& f);
    
    […]
    template<class F> packaged_task(F) -> packaged_task<see below>;
    

    -?- Remarks: This deduction guide participates in overload resolution only if &F::operator() is well-formed when treated as an unevaluated operand. In that case, if decltype(&F::operator()) is of the form R(G::*)(A...) cv &opt noexceptopt for a class type G, then the deduced type is packaged_task<R(A...)>.

    […]
    packaged_task(packaged_task&& rhs) noexcept;
    

[2020-02-13; Prague]

LWG improves wording matching Marshall's Mandating paper.

[2020-02-14; Prague]

Do we want a feature test macro for this new feature?

F N A
1 7 6

[Status to Ready on Friday in Prague.]

[2020-11-09 Approved In November virtual meeting. Status changed: Ready → WP.]

Proposed resolution:

This wording is relative to N4849.

  1. Modify 32.10.10 [futures.task], class template packaged_task synopsis, as indicated:

    namespace std {
      […]
      template<class R, class... ArgTypes>
      class packaged_task<R(ArgTypes...)> {
        […]
      };
      
      template<class R, class... ArgTypes>
      packaged_task(R (*)(ArgTypes...)) -> packaged_task<R(ArgTypes...)>;
    
      template<class F> packaged_task(F) -> packaged_task<see below>;
      
      template<class R, class... ArgTypes>
        void swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y) noexcept;
    }
    
  2. Modify 32.10.10.2 [futures.task.members] as indicated:

    template<class F>
      packaged_task(F&& f);
    
    […]
    template<class F> packaged_task(F) -> packaged_task<see below>;
    

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

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

    […]
    packaged_task(packaged_task&& rhs) noexcept;