deductiongu...ckaged_task(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… deductionguidesforstd::packaged_task πŸ’…

okay so bestie, welcome to the deductionguidesforstd::packaged_task page from the C++ Standard Libary manual β€” yep, that’s the manual name as it appears up top, iykyk πŸ’– this is the C++ Standard Libary deduction-guides situation, and we’re gonna get through it together.


πŸ’– NAME πŸ’–

deductionguidesforstd::packaged_task β€” deductionguidesforstd::packaged_task. that’s the name, no cap, periodt. πŸ’…


🌸 Synopsis 🌸

Defined in header <future>

template< class R, class... Args >                           (1)
(since C++17)
   packaged_task( R(*)(Args...) ) -> packaged_task<R(Args...)>;

template< class F >                                          (2)
(since C++17)
   packaged_task( F ) -> packaged_task</*see below*/>;

template< class F >                                          (3)
(since C++23)
   packaged_task( F ) -> packaged_task</*see below*/>;

template< class F >                                          (4)
(since C++23)
   packaged_task( F ) -> packaged_task</*see below*/>;

okay so here’s the lineup, bestie β€” four whole deduction guides, each with its own vibe check πŸ‘‘βœ¨

  1. This deduction guide is provided for std::packaged_task to allow deduction from functions. that’s literally its whole job, and it ate. 🫢
  2. This overload participates in overload resolution only if &F::operator() is well-formed when treated as an unevaluated operand and decltype(&F::operator()) is of the form R(G::*)(A...) (optionally cv-qualified, optionally noexcept, optionally lvalue reference qualified). The deduced type is std::packaged_task<R(A...)>. yes, that’s a lot of optionally, but we respect the optionally πŸ’…
  3. This overload participates in overload resolution only if &F::operator() is well-formed when treated as an unevaluated operand and F::operator() is an explicit object parameter function whose type is of form R(G, A...) or R(G, A...) noexcept. The deduced type is std::packaged_task<R(A...)>. explicit object parameter function era, we love to see it 🌈
  4. This overload participates in overload resolution only if &F::operator() is well-formed when treated as an unevaluated operand and F::operator() is a static member function whose type is of form R(A...) or R(A...) noexcept. The deduced type is std::packaged_task<R(A...)>. static member function representation, iconic behavior ⭐

πŸ¦‹ Notes πŸ¦‹

⚠️ important vibe check: these deduction guides do not allow deduction from a function with ellipsis parameter, and the ... in the types is always treated as a pack expansion. that’s not a maybe, that’s the rule. πŸ’€

πŸŽ€ Example πŸŽ€

// Run this code

#include <future>

int func(double) { return 0; }

int main()
{
    std::packaged_task f{func}; // deduces packaged_task<int(double)>

    int i = 5;
    std::packaged_task g = [&](double) { return i; }; // => packaged_task<int(double)>
}

alright bestie, that’s the whole page! 🫢 source/version: http://cppreference.com; date: 2024.06.10. the footer also had deductiongu...ckaged_task(3) on it, but we already shouted out the title up top. mwah! πŸ’‹βœ¨πŸŽ€

πŸ“¦ where this page comes from