CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Thu, 24 Jul 2025 01:06:43 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/future/packaged_task/packaged_task/
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 24 Jul 2025 01:06:43 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"8314-CiyHPWJv14lRM0nYkt5ZlZ9q9Zs"
Content-Encoding: gzip
Constructs a packaged_task:
Versions (2) and (3) are never called if the decay type of Fn is the packaged_task.
Output:
Depending on the library implementation, this member function may throw exceptions on certain conditions (such as bad_alloc on a failure to allocate memory).
Neither the default (1) nor the move constructor (5) throw exceptions (no-throw guarantee).
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
<future>
classes
-
futureC++11
-
future_errorC++11
-
packaged_taskC++11
-
promiseC++11
-
shared_futureC++11
-
enum classes
-
future_errcC++11
-
future_statusC++11
-
launchC++11
-
functions
-
asyncC++11
-
future_categoryC++11
-
packaged_task
-
packaged_task::~packaged_taskC++11
-
packaged_task::packaged_taskC++11
member functions
-
packaged_task::get_futureC++11
-
packaged_task::make_ready_at_thread_exitC++11
-
packaged_task::operator()C++11
-
packaged_task::operator=C++11
-
packaged_task::resetC++11
-
packaged_task::swapC++11
-
packaged_task::validC++11
-
non-member overloads
-
swap (packaged_task)C++11
-
non-member specializations
- Reference
- <future>
- packaged_task
- packaged_task
public member function
<future>
std::packaged_task::packaged_task
default (1) | packaged_task() noexcept; |
---|---|
initialization (2) | template <class Fn> explicit packaged_task (Fn&& fn); |
with allocator (3) | template <class Fn, class Alloc> explicit packaged_task (allocator_arg_t aa, const Alloc& alloc, Fn&& fn); |
copy [deleted] (4) | packaged_task (packaged_task&) = delete; |
move (5) | packaged_task (packaged_task&& x) noexcept; |
default (1) | packaged_task() noexcept; |
---|---|
initialization (2) | template <class Fn> explicit packaged_task (Fn&& fn); |
with allocator (3) | template <class Fn, class Alloc> explicit packaged_task (allocator_arg_t aa, const Alloc& alloc, Fn&& fn); |
copy [deleted] (4) | packaged_task (const packaged_task&) = delete; |
move (5) | packaged_task (packaged_task&& x) noexcept; |
Construct packaged task
- (1) default constructor
- The object is initialized with no shared state and no stored task.
- (2) initialization constructor
- The object has a shared state, and its stored task is initialized to fn.
-
- (3) initialization constructor with allocator
- Same as (2), but uses alloc to allocate memory for the internal data structures.
- (4) copy constructor [deleted]
- packaged_task objects cannot be copied (deleted constructor).
- (5) move constructor
- The constructed object acquires the shared state of x (if any), and its stored task is moved.
x is left with no shared state.
Versions (2) and (3) are never called if the decay type of Fn is the packaged_task.
Parameters
- fn
- A callable pointer to function, pointer to member, or any kind of move-constructible function object (i.e., an object whose class defines operator(), including closures and function objects).
The return type and arguments taken by this function shall correspond to the packaged_task's template parameters (Ret and Args...).
The stored task is set to fn (internally initialized withstd::forward<Fn>(fn)
).
- aa
- The std::allocator_arg value. This constant value is merely used to explicitly select this constructor overload.
- alloc
- Allocator object.
The container keeps and uses an internal copy of this allocator, and uses it to allocate storage for its internal data structures. - x
- Another packaged_task object of the same type (with the same template parameters, Ret and Args).
Example
|
|
Output:
The double of 10 is 20. |
Data races
The move constructor (5) modifies x.Exception safety
Strong guarantee: no effects in case an exception is thrown.Depending on the library implementation, this member function may throw exceptions on certain conditions (such as bad_alloc on a failure to allocate memory).
Neither the default (1) nor the move constructor (5) throw exceptions (no-throw guarantee).
See also
- packaged_task::operator=
- Move-assign packaged_task (public member function)
- packaged_task::swap
- Swap packaged_task (public member function)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us