29 #ifndef _GLIBCXX_FUTURE 30 #define _GLIBCXX_FUTURE 1 32 #pragma GCC system_header 34 #if __cplusplus < 201103L 47 #include <bits/shared_ptr.h> 49 #include <bits/uses_allocator.h> 53 namespace std _GLIBCXX_VISIBILITY(default)
55 _GLIBCXX_BEGIN_NAMESPACE_VERSION
68 future_already_retrieved = 1,
69 promise_already_satisfied,
84 make_error_code(future_errc __errc) noexcept
107 what()
const noexcept;
110 code()
const noexcept {
return _M_code; }
115 :
logic_error(
"std::future_error: " + __ec.message()), _M_code(__ec)
118 friend void __throw_future_error(
int);
124 template<
typename _Res>
127 template<
typename _Res>
130 template<
typename _Signature>
133 template<
typename _Res>
145 return static_cast<launch>(
146 static_cast<int>(__x) & static_cast<int>(__y));
151 return static_cast<launch>(
152 static_cast<int>(__x) | static_cast<int>(__y));
157 return static_cast<launch>(
158 static_cast<int>(__x) ^ static_cast<int>(__y));
162 {
return static_cast<launch>(~static_cast<
int>(__x)); }
165 {
return __x = __x & __y; }
168 {
return __x = __x | __y; }
171 {
return __x = __x ^ __y; }
183 template<
typename _Fn,
typename... _Args>
184 using __async_result_of =
typename __invoke_result<
185 typename decay<_Fn>::type,
typename decay<_Args>::type...>::type;
187 template<
typename _Fn,
typename... _Args>
188 future<__async_result_of<_Fn, _Args...>>
189 async(
launch __policy, _Fn&& __fn, _Args&&... __args);
191 template<
typename _Fn,
typename... _Args>
192 future<__async_result_of<_Fn, _Args...>>
193 async(_Fn&& __fn, _Args&&... __args);
195 #if defined(_GLIBCXX_HAS_GTHREADS) 209 virtual void _M_destroy() = 0;
213 void operator()(
_Result_base* __fr)
const { __fr->_M_destroy(); }
222 template<
typename _Res>
226 template<
typename _Res>
230 __gnu_cxx::__aligned_buffer<_Res> _M_storage;
234 typedef _Res result_type;
236 _Result() noexcept : _M_initialized() { }
246 _M_value() noexcept {
return *_M_storage._M_ptr(); }
249 _M_set(
const _Res& __res)
251 ::new (_M_storage._M_addr()) _Res(__res);
252 _M_initialized =
true;
258 ::new (_M_storage._M_addr()) _Res(
std::move(__res));
259 _M_initialized =
true;
263 void _M_destroy() {
delete this; }
267 template<
typename _Res,
typename _Alloc>
270 using __allocator_type = __alloc_rebind<_Alloc, _Result_alloc>;
279 __allocator_type __a(*
this);
286 template<
typename _Res,
typename _Allocator>
288 _S_allocate_result(
const _Allocator& __a)
291 typename __result_type::__allocator_type __a2(__a);
293 __result_type* __p = ::new((
void*)__guard.get()) __result_type{__a};
299 template<
typename _Res,
typename _Tp>
313 enum _Status :
unsigned {
319 __atomic_futex_unsigned<> _M_status;
324 _State_baseV2() noexcept : _M_result(), _M_status(_Status::__not_ready)
326 _State_baseV2(
const _State_baseV2&) =
delete;
327 _State_baseV2& operator=(
const _State_baseV2&) =
delete;
328 virtual ~_State_baseV2() =
default;
337 _M_status._M_load_when_equal(_Status::__ready, memory_order_acquire);
341 template<
typename _Rep,
typename _Period>
347 if (_M_status._M_load(memory_order_acquire) == _Status::__ready)
348 return future_status::ready;
350 if (_M_is_deferred_future())
351 return future_status::deferred;
354 if (__rel > __rel.zero()
355 && _M_status._M_load_when_equal_for(_Status::__ready,
356 memory_order_acquire,
370 return future_status::ready;
372 return future_status::timeout;
375 template<
typename _Clock,
typename _Duration>
379 #if __cplusplus > 201703L 380 static_assert(chrono::is_clock_v<_Clock>);
384 if (_M_status._M_load(memory_order_acquire) == _Status::__ready)
385 return future_status::ready;
387 if (_M_is_deferred_future())
388 return future_status::deferred;
390 if (_M_status._M_load_when_equal_until(_Status::__ready,
391 memory_order_acquire,
399 return future_status::ready;
401 return future_status::timeout;
407 _M_set_result(
function<_Ptr_type()> __res,
bool __ignore_failure =
false)
409 bool __did_set =
false;
412 call_once(_M_once, &_State_baseV2::_M_do_set,
this,
416 _M_status._M_store_notify_all(_Status::__ready,
417 memory_order_release);
418 else if (!__ignore_failure)
419 __throw_future_error(
int(future_errc::promise_already_satisfied));
426 _M_set_delayed_result(
function<_Ptr_type()> __res,
429 bool __did_set =
false;
433 call_once(_M_once, &_State_baseV2::_M_do_set,
this,
436 __throw_future_error(
int(future_errc::promise_already_satisfied));
437 __mr->_M_shared_state =
std::move(__self);
444 _M_break_promise(_Ptr_type __res)
446 if (static_cast<bool>(__res))
454 _M_result.swap(__res);
456 _M_status._M_store_notify_all(_Status::__ready,
457 memory_order_release);
463 _M_set_retrieved_flag()
465 if (_M_retrieved.test_and_set())
466 __throw_future_error(
int(future_errc::future_already_retrieved));
469 template<
typename _Res,
typename _Arg>
473 template<
typename _Res,
typename _Arg>
474 struct _Setter<_Res, _Arg&>
480 "Invalid specialisation");
485 _M_promise->_M_storage->_M_set(*_M_arg);
486 return std::move(_M_promise->_M_storage);
493 template<
typename _Res>
494 struct _Setter<_Res, _Res&&>
499 _M_promise->_M_storage->_M_set(
std::move(*_M_arg));
500 return std::move(_M_promise->_M_storage);
507 template<
typename _Res>
508 struct _Setter<_Res, void>
513 {
return std::move(_M_promise->_M_storage); }
518 struct __exception_ptr_tag { };
521 template<
typename _Res>
522 struct _Setter<_Res, __exception_ptr_tag>
527 _M_promise->_M_storage->_M_error = *_M_ex;
528 return std::move(_M_promise->_M_storage);
535 template<
typename _Res,
typename _Arg>
536 static _Setter<_Res, _Arg&&>
539 _S_check(__prom->_M_future);
543 template<
typename _Res>
544 static _Setter<_Res, __exception_ptr_tag>
547 _S_check(__prom->_M_future);
548 return _Setter<_Res, __exception_ptr_tag>{ __prom, &__ex };
551 template<
typename _Res>
552 static _Setter<_Res, void>
555 _S_check(__prom->_M_future);
556 return _Setter<_Res, void>{ __prom };
559 template<
typename _Tp>
563 if (!static_cast<bool>(__p))
564 __throw_future_error((
int)future_errc::no_state);
570 _M_do_set(
function<_Ptr_type()>* __f,
bool* __did_set)
572 _Ptr_type __res = (*__f)();
577 _M_result.
swap(__res);
581 virtual void _M_complete_async() { }
584 virtual bool _M_is_deferred_future()
const {
return false; }
586 struct _Make_ready final : __at_thread_exit_elt
589 static void _S_run(
void*);
594 #ifdef _GLIBCXX_ASYNC_ABI_COMPAT 596 class _Async_state_common;
598 using _State_base = _State_baseV2;
599 class _Async_state_commonV2;
602 template<
typename _BoundFn,
603 typename _Res = decltype(std::declval<_BoundFn&>()())>
604 class _Deferred_state;
606 template<
typename _BoundFn,
607 typename _Res = decltype(std::declval<_BoundFn&>()())>
608 class _Async_state_impl;
610 template<
typename _Signature>
611 class _Task_state_base;
613 template<
typename _Fn,
typename _Alloc,
typename _Signature>
616 template<
typename _BoundFn>
618 _S_make_deferred_state(_BoundFn&& __fn);
620 template<
typename _BoundFn>
622 _S_make_async_state(_BoundFn&& __fn);
624 template<
typename _Res_ptr,
typename _Fn,
625 typename _Res =
typename _Res_ptr::element_type::result_type>
628 template<
typename _Res_ptr,
typename _BoundFn>
629 static _Task_setter<_Res_ptr, _BoundFn>
630 _S_task_setter(_Res_ptr& __ptr, _BoundFn& __call)
637 template<
typename _Res>
640 typedef _Res& result_type;
642 _Result() noexcept : _M_value_ptr() { }
645 _M_set(_Res& __res) noexcept
648 _Res& _M_get() noexcept {
return *_M_value_ptr; }
653 void _M_destroy() {
delete this; }
660 typedef void result_type;
663 void _M_destroy() {
delete this; }
666 #ifndef _GLIBCXX_ASYNC_ABI_COMPAT 669 template<
typename _Res,
typename _Arg>
671 <__future_base::_State_base::_Setter<_Res, _Arg>>
675 template<
typename _Res_ptr,
typename _Fn,
typename _Res>
677 <__future_base::_Task_setter<_Res_ptr, _Fn, _Res>>
681 template<
typename _Res>
689 __state_type _M_state;
697 valid()
const noexcept {
return static_cast<bool>(_M_state); }
702 _State_base::_S_check(_M_state);
706 template<
typename _Rep,
typename _Period>
710 _State_base::_S_check(_M_state);
711 return _M_state->wait_for(__rel);
714 template<
typename _Clock,
typename _Duration>
718 _State_base::_S_check(_M_state);
719 return _M_state->wait_until(__abs);
727 _State_base::_S_check(_M_state);
729 if (!(__res._M_error == 0))
731 return static_cast<__result_type
>(__res);
736 _M_state.
swap(__that._M_state);
743 _State_base::_S_check(_M_state);
744 _M_state->_M_set_retrieved_flag();
763 explicit _Reset(
__basic_future& __fut) noexcept : _M_fut(__fut) { }
764 ~_Reset() { _M_fut._M_state.reset(); }
771 template<
typename _Res>
775 template<
typename>
friend class packaged_task;
776 template<
typename _Fn,
typename... _Args>
777 friend future<__async_result_of<_Fn, _Args...>>
784 future(
const __state_type& __state) : _Base_type(__state) { }
787 constexpr
future() noexcept : _Base_type() { }
806 typename _Base_type::_Reset __reset(*
this);
807 return std::move(this->_M_get_result()._M_value());
814 template<
typename _Res>
818 template<
typename>
friend class packaged_task;
819 template<
typename _Fn,
typename... _Args>
820 friend future<__async_result_of<_Fn, _Args...>>
827 future(
const __state_type& __state) : _Base_type(__state) { }
830 constexpr
future() noexcept : _Base_type() { }
849 typename _Base_type::_Reset __reset(*
this);
850 return this->_M_get_result()._M_get();
861 template<
typename>
friend class packaged_task;
862 template<
typename _Fn,
typename... _Args>
863 friend future<__async_result_of<_Fn, _Args...>>
870 future(
const __state_type& __state) : _Base_type(__state) { }
873 constexpr
future() noexcept : _Base_type() { }
892 typename _Base_type::_Reset __reset(*
this);
893 this->_M_get_result();
901 template<
typename _Res>
936 get()
const {
return this->_M_get_result()._M_value(); }
940 template<
typename _Res>
975 get()
const {
return this->_M_get_result()._M_get(); }
1014 get()
const { this->_M_get_result(); }
1018 template<
typename _Res>
1021 : _M_state(__sf._M_state)
1024 template<
typename _Res>
1030 template<
typename _Res>
1038 template<
typename _Res>
1043 template<
typename _Res>
1053 template<
typename _Res>
1056 typedef __future_base::_State_base _State;
1059 template<
typename,
typename>
friend class _State::_Setter;
1063 _Ptr_type _M_storage;
1067 : _M_future(std::make_shared<_State>()),
1068 _M_storage(
new _Res_type())
1072 : _M_future(
std::move(__rhs._M_future)),
1076 template<
typename _Allocator>
1078 : _M_future(std::allocate_shared<_State>(__a)),
1079 _M_storage(__future_base::_S_allocate_result<_Res>(__a))
1082 template<
typename _Allocator>
1084 : _M_future(
std::move(__rhs._M_future)),
1092 if (static_cast<bool>(_M_future) && !_M_future.unique())
1093 _M_future->_M_break_promise(
std::move(_M_storage));
1098 operator=(
promise&& __rhs) noexcept
1109 _M_future.
swap(__rhs._M_future);
1110 _M_storage.swap(__rhs._M_storage);
1120 set_value(
const _Res& __r)
1121 { _M_future->_M_set_result(_State::__setter(
this, __r)); }
1124 set_value(_Res&& __r)
1125 { _M_future->_M_set_result(_State::__setter(
this,
std::move(__r))); }
1129 { _M_future->_M_set_result(_State::__setter(__p,
this)); }
1132 set_value_at_thread_exit(
const _Res& __r)
1134 _M_future->_M_set_delayed_result(_State::__setter(
this, __r),
1139 set_value_at_thread_exit(_Res&& __r)
1141 _M_future->_M_set_delayed_result(
1142 _State::__setter(
this,
std::move(__r)), _M_future);
1148 _M_future->_M_set_delayed_result(_State::__setter(__p,
this),
1153 template<
typename _Res>
1158 template<
typename _Res,
typename _Alloc>
1164 template<
typename _Res>
1165 class promise<_Res&>
1167 typedef __future_base::_State_base _State;
1170 template<
typename,
typename>
friend class _State::_Setter;
1174 _Ptr_type _M_storage;
1178 : _M_future(std::make_shared<_State>()),
1179 _M_storage(
new _Res_type())
1182 promise(promise&& __rhs) noexcept
1183 : _M_future(
std::move(__rhs._M_future)),
1187 template<
typename _Allocator>
1189 : _M_future(std::allocate_shared<_State>(__a)),
1190 _M_storage(__future_base::_S_allocate_result<_Res&>(__a))
1193 template<
typename _Allocator>
1195 : _M_future(
std::move(__rhs._M_future)),
1199 promise(
const promise&) =
delete;
1203 if (static_cast<bool>(_M_future) && !_M_future.unique())
1204 _M_future->_M_break_promise(
std::move(_M_storage));
1209 operator=(promise&& __rhs) noexcept
1215 promise& operator=(
const promise&) =
delete;
1218 swap(promise& __rhs) noexcept
1220 _M_future.
swap(__rhs._M_future);
1221 _M_storage.
swap(__rhs._M_storage);
1231 set_value(_Res& __r)
1232 { _M_future->_M_set_result(_State::__setter(
this, __r)); }
1236 { _M_future->_M_set_result(_State::__setter(__p,
this)); }
1239 set_value_at_thread_exit(_Res& __r)
1241 _M_future->_M_set_delayed_result(_State::__setter(
this, __r),
1248 _M_future->_M_set_delayed_result(_State::__setter(__p,
this),
1257 typedef __future_base::_State_base _State;
1260 template<
typename,
typename>
friend class _State::_Setter;
1264 _Ptr_type _M_storage;
1268 : _M_future(std::make_shared<_State>()),
1269 _M_storage(
new _Res_type())
1272 promise(promise&& __rhs) noexcept
1273 : _M_future(
std::move(__rhs._M_future)),
1277 template<
typename _Allocator>
1279 : _M_future(std::allocate_shared<_State>(__a)),
1280 _M_storage(__future_base::_S_allocate_result<void>(__a))
1285 template<
typename _Allocator>
1287 : _M_future(
std::move(__rhs._M_future)),
1291 promise(
const promise&) =
delete;
1295 if (static_cast<bool>(_M_future) && !_M_future.unique())
1296 _M_future->_M_break_promise(
std::move(_M_storage));
1301 operator=(promise&& __rhs) noexcept
1307 promise& operator=(
const promise&) =
delete;
1310 swap(promise& __rhs) noexcept
1312 _M_future.
swap(__rhs._M_future);
1313 _M_storage.
swap(__rhs._M_storage);
1324 { _M_future->_M_set_result(_State::__setter(
this)); }
1328 { _M_future->_M_set_result(_State::__setter(__p,
this)); }
1331 set_value_at_thread_exit()
1332 { _M_future->_M_set_delayed_result(_State::__setter(
this), _M_future); }
1337 _M_future->_M_set_delayed_result(_State::__setter(__p,
this),
1342 template<
typename _Ptr_type,
typename _Fn,
typename _Res>
1343 struct __future_base::_Task_setter
1350 (*_M_result)->_M_set((*_M_fn)());
1354 __throw_exception_again;
1366 template<
typename _Ptr_type,
typename _Fn>
1367 struct __future_base::_Task_setter<_Ptr_type, _Fn, void>
1369 _Ptr_type operator()()
const 1377 __throw_exception_again;
1385 _Ptr_type* _M_result;
1390 template<
typename _Res,
typename... _Args>
1391 struct __future_base::_Task_state_base<_Res(_Args...)>
1392 : __future_base::_State_base
1396 template<
typename _Alloc>
1397 _Task_state_base(
const _Alloc& __a)
1398 : _M_result(_S_allocate_result<_Res>(__a))
1403 _M_run(_Args&&... __args) = 0;
1413 _Ptr_type _M_result;
1417 template<
typename _Fn,
typename _Alloc,
typename _Res,
typename... _Args>
1418 struct __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)> final
1419 : __future_base::_Task_state_base<_Res(_Args...)>
1421 template<
typename _Fn2>
1422 _Task_state(_Fn2&& __fn,
const _Alloc& __a)
1423 : _Task_state_base<_Res(_Args...)>(__a),
1424 _M_impl(std::forward<_Fn2>(__fn), __a)
1429 _M_run(_Args&&... __args)
1431 auto __boundfn = [&] () -> _Res {
1432 return std::__invoke_r<_Res>(_M_impl._M_fn,
1433 std::forward<_Args>(__args)...);
1435 this->_M_set_result(_S_task_setter(this->_M_result, __boundfn));
1441 auto __boundfn = [&] () -> _Res {
1442 return std::__invoke_r<_Res>(_M_impl._M_fn,
1443 std::forward<_Args>(__args)...);
1445 this->_M_set_delayed_result(_S_task_setter(this->_M_result, __boundfn),
1449 virtual shared_ptr<_Task_state_base<_Res(_Args...)>>
1452 struct _Impl : _Alloc
1454 template<
typename _Fn2>
1455 _Impl(_Fn2&& __fn,
const _Alloc& __a)
1456 : _Alloc(__a), _M_fn(std::forward<_Fn2>(__fn)) { }
1461 template<
typename _Signature,
typename _Fn,
1464 __create_task_state(_Fn&& __fn,
const _Alloc& __a = _Alloc())
1466 typedef typename decay<_Fn>::type _Fn2;
1467 typedef __future_base::_Task_state<_Fn2, _Alloc, _Signature> _State;
1468 return std::allocate_shared<_State>(__a, std::forward<_Fn>(__fn), __a);
1471 template<
typename _Fn,
typename _Alloc,
typename _Res,
typename... _Args>
1472 shared_ptr<__future_base::_Task_state_base<_Res(_Args...)>>
1473 __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)>::_M_reset()
1475 return __create_task_state<_Res(_Args...)>(
std::move(_M_impl._M_fn),
1476 static_cast<_Alloc&
>(_M_impl));
1480 template<
typename _Res,
typename... _ArgTypes>
1481 class packaged_task<_Res(_ArgTypes...)>
1483 typedef __future_base::_Task_state_base<_Res(_ArgTypes...)> _State_type;
1488 template<
typename _Fn,
typename _Fn2 = __remove_cvref_t<_Fn>>
1494 packaged_task() noexcept { }
1496 template<
typename _Fn,
typename = __not_same<_Fn>>
1498 packaged_task(_Fn&& __fn)
1500 __create_task_state<_Res(_ArgTypes...)>(std::forward<_Fn>(__fn)))
1503 #if __cplusplus < 201703L 1508 template<
typename _Fn,
typename _Alloc,
typename = __not_same<_Fn>>
1510 : _M_state(__create_task_state<_Res(_ArgTypes...)>(
1511 std::forward<_Fn>(__fn), __a))
1516 template<
typename _Allocator>
1520 template<
typename _Allocator>
1522 const packaged_task&) =
delete;
1524 template<
typename _Allocator>
1526 packaged_task&& __other) noexcept
1527 { this->swap(__other); }
1532 if (static_cast<bool>(_M_state) && !_M_state.unique())
1533 _M_state->_M_break_promise(
std::move(_M_state->_M_result));
1537 packaged_task(
const packaged_task&) =
delete;
1538 packaged_task& operator=(
const packaged_task&) =
delete;
1541 packaged_task(packaged_task&& __other) noexcept
1542 { this->swap(__other); }
1544 packaged_task& operator=(packaged_task&& __other) noexcept
1546 packaged_task(
std::move(__other)).swap(*
this);
1551 swap(packaged_task& __other) noexcept
1552 { _M_state.
swap(__other._M_state); }
1555 valid()
const noexcept
1556 {
return static_cast<bool>(_M_state); }
1565 operator()(_ArgTypes... __args)
1567 __future_base::_State_base::_S_check(_M_state);
1568 _M_state->_M_run(std::forward<_ArgTypes>(__args)...);
1572 make_ready_at_thread_exit(_ArgTypes... __args)
1574 __future_base::_State_base::_S_check(_M_state);
1575 _M_state->_M_run_delayed(std::forward<_ArgTypes>(__args)..., _M_state);
1581 __future_base::_State_base::_S_check(_M_state);
1582 packaged_task __tmp;
1583 __tmp._M_state = _M_state;
1584 _M_state = _M_state->_M_reset();
1589 template<
typename _Res,
typename... _ArgTypes>
1591 swap(packaged_task<_Res(_ArgTypes...)>& __x,
1592 packaged_task<_Res(_ArgTypes...)>& __y) noexcept
1595 #if __cplusplus < 201703L 1598 template<
typename _Res,
typename _Alloc>
1605 template<
typename _BoundFn,
typename _Res>
1606 class __future_base::_Deferred_state final
1607 :
public __future_base::_State_base
1611 _Deferred_state(_BoundFn&& __fn)
1612 : _M_result(
new _Result<_Res>()), _M_fn(
std::move(__fn))
1617 _Ptr_type _M_result;
1630 _M_set_result(_S_task_setter(_M_result, _M_fn),
true);
1635 virtual bool _M_is_deferred_future()
const {
return true; }
1639 class __future_base::_Async_state_commonV2
1640 :
public __future_base::_State_base
1643 ~_Async_state_commonV2() =
default;
1660 virtual void _M_complete_async() { _M_join(); }
1662 void _M_join() {
std::call_once(_M_once, &thread::join, &_M_thread); }
1670 template<
typename _BoundFn,
typename _Res>
1671 class __future_base::_Async_state_impl final
1672 :
public __future_base::_Async_state_commonV2
1676 _Async_state_impl(_BoundFn&& __fn)
1677 : _M_result(
new _Result<_Res>()), _M_fn(
std::move(__fn))
1682 _M_set_result(_S_task_setter(_M_result, _M_fn));
1687 if (static_cast<bool>(_M_result))
1688 this->_M_break_promise(
std::move(_M_result));
1689 __throw_exception_again;
1697 ~_Async_state_impl() {
if (_M_thread.joinable()) _M_thread.join(); }
1701 _Ptr_type _M_result;
1705 template<
typename _BoundFn>
1707 __future_base::_S_make_deferred_state(_BoundFn&& __fn)
1709 typedef typename remove_reference<_BoundFn>::type __fn_type;
1710 typedef _Deferred_state<__fn_type> __state_type;
1711 return std::make_shared<__state_type>(
std::move(__fn));
1714 template<
typename _BoundFn>
1716 __future_base::_S_make_async_state(_BoundFn&& __fn)
1718 typedef typename remove_reference<_BoundFn>::type __fn_type;
1719 typedef _Async_state_impl<__fn_type> __state_type;
1720 return std::make_shared<__state_type>(
std::move(__fn));
1725 template<
typename _Fn,
typename... _Args>
1726 _GLIBCXX_NODISCARD
future<__async_result_of<_Fn, _Args...>>
1730 if ((__policy & launch::async) == launch::async)
1734 __state = __future_base::_S_make_async_state(
1735 std::thread::__make_invoker(std::forward<_Fn>(__fn),
1736 std::forward<_Args>(__args)...)
1739 #if __cpp_exceptions 1742 if (__e.code() != errc::resource_unavailable_try_again
1743 || (__policy & launch::deferred) != launch::deferred)
1750 __state = __future_base::_S_make_deferred_state(
1751 std::thread::__make_invoker(std::forward<_Fn>(__fn),
1752 std::forward<_Args>(__args)...));
1754 return future<__async_result_of<_Fn, _Args...>>(__state);
1758 template<
typename _Fn,
typename... _Args>
1759 _GLIBCXX_NODISCARD
inline future<__async_result_of<_Fn, _Args...>>
1762 return std::async(launch::async|launch::deferred,
1763 std::forward<_Fn>(__fn),
1764 std::forward<_Args>(__args)...);
1767 #endif // _GLIBCXX_ASYNC_ABI_COMPAT 1768 #endif // _GLIBCXX_HAS_GTHREADS 1771 _GLIBCXX_END_NAMESPACE_VERSION
1776 #endif // _GLIBCXX_FUTURE A smart pointer with reference-counted copy semantics.
Declare uses_allocator so it can be specialized in <queue> etc.
future_errc
Error code for futures.
shared_future(future< _Res > &&__uf) noexcept
Construct from a future rvalue.
20.7.1.2 unique_ptr for single objects.
void call_once(once_flag &__once, _Callable &&__f, _Args &&... __args)
Invoke a callable and synchronize with other calls using the same flag.
future_status
Status code for futures.
Partial specialization for shared_future<R&>
One of two subclasses of exception.
future(future &&__uf) noexcept
Move constructor.
Non-standard RAII type for managing pointers obtained from allocators.
Thrown as part of forced unwinding.A magic placeholder class that can be caught by reference to recog...
shared_future(future< void > &&__uf) noexcept
Construct from a future rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr _Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
Explicit specialization for void.
The standard allocator, as per [20.4].
A result object that has storage for an object of type _Res.
shared_future(shared_future &&__sf) noexcept
Construct from a shared_future rvalue.
Explicit specialization for future<void>
Base class and enclosing scope.
Common implementation for future and shared_future.
Primary template for shared_future.
future< __async_result_of< _Fn, _Args... > > async(_Fn &&__fn, _Args &&... __args)
async, potential overload
void swap(unique_ptr &__u) noexcept
Exchange the pointer and deleter with another object.
An opaque pointer to an arbitrary exception.
Define a member typedef type only if a boolean constant is true.
shared_future(const shared_future &__sf)
Copy constructor.
Explicit specialization for shared_future<void>
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
const error_category & future_category() noexcept
Points to a statically-allocated object derived from error_category.
shared_future(const shared_future &__sf)
Copy constructor.
future(future &&__uf) noexcept
Move constructor.
exception_ptr make_exception_ptr(_Ex) noexcept
Obtain an exception_ptr pointing to a copy of the supplied object.
shared_future(shared_future &&__sf) noexcept
Construct from a shared_future rvalue.
Primary template for future.
Partial specialization for reference types.
Flag type used by std::call_once.
shared_future(shared_future &&__sf) noexcept
Construct from a shared_future rvalue.
bitset< _Nb > operator &(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
__result_type _M_get_result() const
Wait for the state to be ready and rethrow any stored exception.
error_condition make_error_condition(future_errc __errc) noexcept
Overload for make_error_condition.
shared_future(future< _Res &> &&__uf) noexcept
Construct from a future rvalue.
exception_ptr current_exception() noexcept
__allocated_ptr< _Alloc > __allocate_guarded(_Alloc &__a)
Allocate space for a single object using __a.
void swap(shared_ptr< _Tp > &__a, shared_ptr< _Tp > &__b) noexcept
Swap overload for shared_ptr.
Exception type thrown by futures.
ISO C++ entities toplevel namespace is std.
future< __async_result_of< _Fn, _Args... > > async(launch __policy, _Fn &&__fn, _Args &&... __args)
async
bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
launch
Launch code for futures.
future(future &&__uf) noexcept
Move constructor.
Partial specialization for future<R&>
Primary template for promise.
void rethrow_exception(exception_ptr)
Throw the object pointed to by the exception_ptr.
void swap(packaged_task< _Res(_ArgTypes...)> &__x, packaged_task< _Res(_ArgTypes...)> &__y) noexcept
swap
A result object that uses an allocator.
An exception type that includes an error_code value.
shared_future(const shared_future &__sf) noexcept
Copy constructor.