std::experi...amentalsTS)(3)

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

πŸ’– NAME πŸ’–

std::experimental::packaged_task::packaged_task(libraryfundamentalsTS) - std::experimental::packaged_task::packaged_task(libraryfundamentalsTS)

okay so welcome to the C++ Standard Libary corner of cppreference β€” yes, β€œLibary,” typo preserved, it’s iconic πŸ’… β€” and this is the constructor page for the library fundamentals TS version of std::experimental::packaged_task. It’s giving β€œfive overloads and main character energy,” fr fr. ✨

πŸ¦‹ Synopsis πŸ¦‹

          packaged_task() noexcept;                              (1) (library
       fundamentals TS)
          template< class F >                                    (2) (library
       fundamentals TS)
          explicit packaged_task( F&& f );
          template< class F, class Allocator >
          explicit packaged_task( std::allocator_arg_t, const    (3) (library
          Allocator& alloc, F&& f );
          packaged_task( const packaged_task& ) = delete;        (4) (library
       fundamentals TS)
          packaged_task( packaged_task&& rhs ) noexcept;         (5) (library
       fundamentals TS)

Constructs a new std::experimental::packaged_task object. Bestie, that’s the whole vibe, but here’s the breakdown so you know exactly which overload is doing what πŸ‘‡

  1. Constructs a std::experimental::packaged_task object with no task and no shared state.
  2. Constructs a std::experimental::packaged_task object with a shared state and a copy of the task, initialized with std::forward<F>(f). This constructor does not participate in overload resolution if std::decay<F>::type is the same type as std::packaged_task<R(ArgTypes...)>.
  3. Constructs a std::experimental::packaged_task object with a shared state and a copy of the task, initialized with std::forward<F>(f). Uses the provided allocator to allocate memory necessary to store the task, which is treated as a type-erased allocator (see below). This constructor does not participate in overload resolution if std::decay<F>::type is the same type as std::packaged_task<R(ArgTypes...)>.
  4. The copy constructor is deleted, std::experimental::packaged_task is move-only.
  5. Constructs a std::experimental::packaged_task with the shared state and task formerly owned by rhs, leaving rhs with no shared state and a moved-from task.

🧚 Type-erased allocator 🧚

The constructors of packaged_task taking an allocator argument alloc treats that argument as a type-erased allocator. The memory resource pointer used by packaged_task to allocate memory is determined using the allocator argument (if specified) as follows:

  • Type of alloc: Non-existent (no allocator specified at time of construction). Value of the memory resource pointer: The value of std::experimental::pmr::get_default_resource() at time of construction.
  • Type of alloc: std::nullptr_t. Value of the memory resource pointer: The value of std::experimental::pmr::get_default_resource() at time of construction.
  • Type of alloc: A pointer type convertible to std::experimental::pmr::memory_resource*. Value of the memory resource pointer: static_cast<std::experimental::pmr::memory_resource*>(alloc).
  • Type of alloc: std::experimental::pmr::memory_resource*. Value of the memory resource pointer: alloc.
  • Type of alloc: A specialization of std::experimental::pmr::polymorphic_allocator. Value of the memory resource pointer: alloc.resource().
  • Type of alloc: Any other type meeting the Allocator requirements. Value of the memory resource pointer: A pointer to a value of type std::experimental::pmr::resource_adaptor<A>(alloc), where A is the type of alloc. The pointer remains valid only for the lifetime of the packaged_task object.
  • Type of alloc: None of the above. Value of the memory resource pointer: The program is ill-formed.

πŸŽ€ Parameters πŸŽ€

  • f β€” the callable target (function, member function, lambda-expression, functor) to execute.
  • alloc β€” the allocator to use when storing the task.
  • rhs β€” the std::experimental::packaged_task to move from.

πŸ’€ Exceptions πŸ’€

  • 2,3) β€” Any exceptions thrown by copy/move constructor of f and possiblly std::bad_alloc if the allocation fails.
  • 4) β€” (none).

source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::experi...amentalsTS)(3) β€” k bye bestie, go construct responsibly πŸ’–βœ¨πŸ«Ά

πŸ“¦ where this page comes from