CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Wed, 23 Jul 2025 11:36:32 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/future/packaged_task/operator_func/
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 23 Jul 2025 11:36:32 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"7b4f-58xxj2/YGtMHKUu1W65dynzi4hc"
Content-Encoding: gzip
Calls the stored task, forwarding args as its arguments.
- If the call to the stored task completes successfully, the value it returns (if any) is stored in the shared state.
- If the call to the stored task throws an exception, the exception is caught and also stored in the shared state.
In both cases, the shared state is made ready (which unblocks any threads currently waiting for it).
The shared state can be accessed by calling get on a future object returned by a previous call to member get_future.
The stored task is generally specified on construction. The effects of calling it depend on its type:
The return value of the stored task (if any) is stored in the shared state.
The shared state is modified as an atomic operation (causing no data races).
This member function throws an exception on the following conditions:
This member function also throws if any copy or movement of the arguments throws and -depending on the library implementation- may also throw to report other situations.
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
- operator()
public member function
<future>
std::packaged_task::operator()
void operator()(Args... args);
Call stored task
- If the call to the stored task completes successfully, the value it returns (if any) is stored in the shared state.
- If the call to the stored task throws an exception, the exception is caught and also stored in the shared state.
In both cases, the shared state is made ready (which unblocks any threads currently waiting for it).
The shared state can be accessed by calling get on a future object returned by a previous call to member get_future.
The stored task is generally specified on construction. The effects of calling it depend on its type:
- If the stored task is a function pointer or a function object, it is called forwarding the arguments to the call.
- If the stored task is a pointer to a non-static member function, it is called using the first argument as the object on which the member is called (this may either be an object, a reference, or a pointer to it), and the remaining arguments are forwarded as arguments for the member function.
- If it is a pointer to a non-static data member, it should be called with a single argument, and the function stores in the shared state a reference to that member of its argument (the argument may either be an object, a reference, or a pointer to it).
Parameters
- args...
- Arguments for the call.
If the type of the stored task is a member pointer, the first argument shall be an object for which that member is defined (or a reference, or a pointer to it).
Args... are the packaged_task template parameters, which represent the types of the arguments for the stored task .
Return value
none.The return value of the stored task (if any) is stored in the shared state.
Data races
The packaged_task is modified.The shared state is modified as an atomic operation (causing no data races).
Exception safety
Basic guarantee: if an exception is thrown, the packaged_task is in a valid state.This member function throws an exception on the following conditions:
exception type | error condition | description |
---|---|---|
future_error | future_errc::no_state | The object has no shared state (it is a default-constructed packaged_task) |
future_error | future_errc::promise_already_satisfied | The stored task has already been called |
See also
- packaged_task::make_ready_at_thread_exit
- Call stored task and make ready at thread exit (public member function)
- packaged_task::get_future
- Get future (public member function)
- future::get
- Get value (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