3// Copyright (C) 2009-2024 Free Software Foundation, Inc.
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
25/** @file include/future
26 * This is a Standard C++ Library header.
29#ifndef _GLIBCXX_FUTURE
30#define _GLIBCXX_FUTURE 1
32#pragma GCC system_header
34#include <bits/requires_hosted.h> // concurrency
36#if __cplusplus < 201103L
37# include <bits/c++0x_warning.h>
40#include <mutex> // call_once
41#include <condition_variable> // __at_thread_exit_elt
42#include <system_error>
43#include <bits/atomic_base.h> // atomic_flag
44#include <bits/allocated_ptr.h>
45#include <bits/atomic_futex.h>
46#include <bits/exception_defines.h>
47#include <bits/invoke.h>
48#include <bits/unique_ptr.h>
49#include <bits/shared_ptr.h>
50#include <bits/std_function.h>
51#include <bits/std_thread.h>
52#include <bits/uses_allocator.h>
53#include <ext/aligned_buffer.h>
55namespace std _GLIBCXX_VISIBILITY(default)
57_GLIBCXX_BEGIN_NAMESPACE_VERSION
60 * @defgroup futures Futures
61 * @ingroup concurrency
63 * Futures and promises provide support for retrieving the result from
64 * an asynchronous function, e.g. one that is running in another thread.
65 * A `std::future` represents an asynchronous result that will become
66 * ready at some later time. A consumer can wait on a future until the
67 * result is ready to be accessed.
73 /// Error code for futures
74 enum class future_errc
76 future_already_retrieved = 1,
77 promise_already_satisfied,
82 /// Specialization that allows `future_errc` to convert to `error_code`.
84 struct is_error_code_enum<future_errc> : public true_type { };
86 /// Points to a statically-allocated object derived from error_category.
87 [[__nodiscard__, __gnu__::__const__]]
89 future_category() noexcept;
91 /// Overload of make_error_code for `future_errc`.
94 make_error_code(future_errc __errc) noexcept
95 { return error_code(static_cast<int>(__errc), future_category()); }
97 /// Overload of make_error_condition for `future_errc`.
99 inline error_condition
100 make_error_condition(future_errc __errc) noexcept
101 { return error_condition(static_cast<int>(__errc), future_category()); }
104 * @brief Exception type thrown by futures.
105 * @ingroup exceptions
108 class future_error : public logic_error
112 future_error(future_errc __errc)
113 : future_error(std::make_error_code(__errc))
116 virtual ~future_error() noexcept;
119 what() const noexcept;
122 code() const noexcept { return _M_code; }
126 future_error(error_code __ec)
127 : logic_error("std::future_error: " + __ec.message()), _M_code(__ec)
130 friend void __throw_future_error(int);
135 // Forward declarations.
136 template<typename _Res>
139 template<typename _Res>
142 template<typename _Signature>
145 template<typename _Res>
148 /// Launch code for futures
156 constexpr launch operator&(launch __x, launch __y) noexcept
158 return static_cast<launch>(
159 static_cast<int>(__x) & static_cast<int>(__y));
163 constexpr launch operator|(launch __x, launch __y) noexcept
165 return static_cast<launch>(
166 static_cast<int>(__x) | static_cast<int>(__y));
170 constexpr launch operator^(launch __x, launch __y) noexcept
172 return static_cast<launch>(
173 static_cast<int>(__x) ^ static_cast<int>(__y));
177 constexpr launch operator~(launch __x) noexcept
178 { return static_cast<launch>(~static_cast<int>(__x)); }
181 inline launch& operator&=(launch& __x, launch __y) noexcept
182 { return __x = __x & __y; }
185 inline launch& operator|=(launch& __x, launch __y) noexcept
186 { return __x = __x | __y; }
189 inline launch& operator^=(launch& __x, launch __y) noexcept
190 { return __x = __x ^ __y; }
192 /// Status code for futures
193 enum class future_status
200 /// @cond undocumented
201 // _GLIBCXX_RESOLVE_LIB_DEFECTS
202 // 2021. Further incorrect usages of result_of
203 template<typename _Fn, typename... _Args>
204 using __async_result_of = typename __invoke_result<
205 typename decay<_Fn>::type, typename decay<_Args>::type...>::type;
208 template<typename _Fn, typename... _Args>
209 future<__async_result_of<_Fn, _Args...>>
210 async(launch __policy, _Fn&& __fn, _Args&&... __args);
212 template<typename _Fn, typename... _Args>
213 future<__async_result_of<_Fn, _Args...>>
214 async(_Fn&& __fn, _Args&&... __args);
216#if defined(_GLIBCXX_HAS_GTHREADS)
218 /// @cond undocumented
220 /// Base class and enclosing scope.
223 /// Base class for results.
226 exception_ptr _M_error;
228 _Result_base(const _Result_base&) = delete;
229 _Result_base& operator=(const _Result_base&) = delete;
231 // _M_destroy() allows derived classes to control deallocation
232 virtual void _M_destroy() = 0;
236 void operator()(_Result_base* __fr) const { __fr->_M_destroy(); }
241 virtual ~_Result_base();
244 /// A unique_ptr for result objects.
245 template<typename _Res>
246 using _Ptr = unique_ptr<_Res, _Result_base::_Deleter>;
248 /// A result object that has storage for an object of type _Res.
249 template<typename _Res>
250 struct _Result : _Result_base
253 __gnu_cxx::__aligned_buffer<_Res> _M_storage;
257 typedef _Res result_type;
259 _Result() noexcept : _M_initialized() { }
267 // Return lvalue, future will add const or rvalue-reference
269 _M_value() noexcept { return *_M_storage._M_ptr(); }
272 _M_set(const _Res& __res)
274 ::new (_M_storage._M_addr()) _Res(__res);
275 _M_initialized = true;
281 ::new (_M_storage._M_addr()) _Res(std::move(__res));
282 _M_initialized = true;
286 void _M_destroy() { delete this; }
289 /// A result object that uses an allocator.
290 template<typename _Res, typename _Alloc>
291 struct _Result_alloc final : _Result<_Res>, _Alloc
293 using __allocator_type = __alloc_rebind<_Alloc, _Result_alloc>;
296 _Result_alloc(const _Alloc& __a) : _Result<_Res>(), _Alloc(__a)
302 __allocator_type __a(*this);
303 __allocated_ptr<__allocator_type> __guard_ptr{ __a, this };
304 this->~_Result_alloc();
308 // Create a result object that uses an allocator.
309 template<typename _Res, typename _Allocator>
310 static _Ptr<_Result_alloc<_Res, _Allocator>>
311 _S_allocate_result(const _Allocator& __a)
313 using __result_type = _Result_alloc<_Res, _Allocator>;
314 typename __result_type::__allocator_type __a2(__a);
315 auto __guard = std::__allocate_guarded(__a2);
316 __result_type* __p = ::new((void*)__guard.get()) __result_type{__a};
318 return _Ptr<__result_type>(__p);
321 // Keep it simple for std::allocator.
322 template<typename _Res, typename _Tp>
323 static _Ptr<_Result<_Res>>
324 _S_allocate_result(const std::allocator<_Tp>&)
326 return _Ptr<_Result<_Res>>(new _Result<_Res>);
329 // Base class for various types of shared state created by an
330 // asynchronous provider (such as a std::promise) and shared with one
331 // or more associated futures.
334 typedef _Ptr<_Result_base> _Ptr_type;
336 enum _Status : unsigned {
342 __atomic_futex_unsigned<> _M_status;
343 atomic_flag _M_retrieved = ATOMIC_FLAG_INIT;
347 _State_baseV2() noexcept : _M_result(), _M_status(_Status::__not_ready)
349 _State_baseV2(const _State_baseV2&) = delete;
350 _State_baseV2& operator=(const _State_baseV2&) = delete;
351 virtual ~_State_baseV2() = default;
356 // Run any deferred function or join any asynchronous thread:
358 // Acquire MO makes sure this synchronizes with the thread that made
360 _M_status._M_load_when_equal(_Status::__ready, memory_order_acquire);
364 template<typename _Rep, typename _Period>
366 wait_for(const chrono::duration<_Rep, _Period>& __rel)
368 // First, check if the future has been made ready. Use acquire MO
369 // to synchronize with the thread that made it ready.
370 if (_M_status._M_load(memory_order_acquire) == _Status::__ready)
371 return future_status::ready;
373 if (_M_is_deferred_future())
374 return future_status::deferred;
376 // Don't wait unless the relative time is greater than zero.
377 if (__rel > __rel.zero()
378 && _M_status._M_load_when_equal_for(_Status::__ready,
379 memory_order_acquire,
382 // _GLIBCXX_RESOLVE_LIB_DEFECTS
383 // 2100. timed waiting functions must also join
384 // This call is a no-op by default except on an async future,
385 // in which case the async thread is joined. It's also not a
386 // no-op for a deferred future, but such a future will never
387 // reach this point because it returns future_status::deferred
388 // instead of waiting for the future to become ready (see
389 // above). Async futures synchronize in this call, so we need
390 // no further synchronization here.
393 return future_status::ready;
395 return future_status::timeout;
398 template<typename _Clock, typename _Duration>
400 wait_until(const chrono::time_point<_Clock, _Duration>& __abs)
402#if __cplusplus > 201703L
403 static_assert(chrono::is_clock_v<_Clock>);
405 // First, check if the future has been made ready. Use acquire MO
406 // to synchronize with the thread that made it ready.
407 if (_M_status._M_load(memory_order_acquire) == _Status::__ready)
408 return future_status::ready;
410 if (_M_is_deferred_future())
411 return future_status::deferred;
413 if (_M_status._M_load_when_equal_until(_Status::__ready,
414 memory_order_acquire,
417 // _GLIBCXX_RESOLVE_LIB_DEFECTS
418 // 2100. timed waiting functions must also join
419 // See wait_for(...) above.
422 return future_status::ready;
424 return future_status::timeout;
427 // Provide a result to the shared state and make it ready.
428 // Calls at most once: _M_result = __res();
430 _M_set_result(function<_Ptr_type()> __res, bool __ignore_failure = false)
432 bool __did_set = false;
433 // all calls to this function are serialized,
434 // side-effects of invoking __res only happen once
435 call_once(_M_once, &_State_baseV2::_M_do_set, this,
436 std::__addressof(__res), std::__addressof(__did_set));
438 // Use release MO to synchronize with observers of the ready state.
439 _M_status._M_store_notify_all(_Status::__ready,
440 memory_order_release);
441 else if (!__ignore_failure)
442 __throw_future_error(int(future_errc::promise_already_satisfied));
445 // Provide a result to the shared state but delay making it ready
446 // until the calling thread exits.
447 // Calls at most once: _M_result = __res();
449 _M_set_delayed_result(function<_Ptr_type()> __res,
450 weak_ptr<_State_baseV2> __self)
452 bool __did_set = false;
453 unique_ptr<_Make_ready> __mr{new _Make_ready};
454 // all calls to this function are serialized,
455 // side-effects of invoking __res only happen once
456 call_once(_M_once, &_State_baseV2::_M_do_set, this,
457 std::__addressof(__res), std::__addressof(__did_set));
459 __throw_future_error(int(future_errc::promise_already_satisfied));
460 __mr->_M_shared_state = std::move(__self);
465 // Abandon this shared state.
467 _M_break_promise(_Ptr_type __res)
469 if (static_cast<bool>(__res))
472 make_exception_ptr(future_error(future_errc::broken_promise));
473 // This function is only called when the last asynchronous result
474 // provider is abandoning this shared state, so noone can be
475 // trying to make the shared state ready at the same time, and
476 // we can access _M_result directly instead of through call_once.
477 _M_result.swap(__res);
478 // Use release MO to synchronize with observers of the ready state.
479 _M_status._M_store_notify_all(_Status::__ready,
480 memory_order_release);
484 // Called when this object is first passed to a future.
486 _M_set_retrieved_flag()
488 if (_M_retrieved.test_and_set())
489 __throw_future_error(int(future_errc::future_already_retrieved));
492 template<typename _Res, typename _Arg>
496 template<typename _Res, typename _Arg>
497 struct _Setter<_Res, _Arg&>
499 // check this is only used by promise<R>::set_value(const R&)
500 // or promise<R&>::set_value(R&)
501 static_assert(is_same<_Res, _Arg&>::value // promise<R&>
502 || is_same<const _Res, _Arg>::value, // promise<R>
503 "Invalid specialisation");
505 // Used by std::promise to copy construct the result.
506 typename promise<_Res>::_Ptr_type operator()() const
508 _M_promise->_M_storage->_M_set(*_M_arg);
509 return std::move(_M_promise->_M_storage);
511 promise<_Res>* _M_promise;
516 template<typename _Res>
517 struct _Setter<_Res, _Res&&>
519 // Used by std::promise to move construct the result.
520 typename promise<_Res>::_Ptr_type operator()() const
522 _M_promise->_M_storage->_M_set(std::move(*_M_arg));
523 return std::move(_M_promise->_M_storage);
525 promise<_Res>* _M_promise;
530 template<typename _Res>
531 struct _Setter<_Res, void>
533 static_assert(is_void<_Res>::value, "Only used for promise<void>");
535 typename promise<_Res>::_Ptr_type operator()() const
536 { return std::move(_M_promise->_M_storage); }
538 promise<_Res>* _M_promise;
541 struct __exception_ptr_tag { };
544 template<typename _Res>
545 struct _Setter<_Res, __exception_ptr_tag>
547 // Used by std::promise to store an exception as the result.
548 typename promise<_Res>::_Ptr_type operator()() const
550 _M_promise->_M_storage->_M_error = *_M_ex;
551 return std::move(_M_promise->_M_storage);
554 promise<_Res>* _M_promise;
555 exception_ptr* _M_ex;
558 template<typename _Res, typename _Arg>
559 __attribute__((__always_inline__))
560 static _Setter<_Res, _Arg&&>
561 __setter(promise<_Res>* __prom, _Arg&& __arg) noexcept
563 return _Setter<_Res, _Arg&&>{ __prom, std::__addressof(__arg) };
566 template<typename _Res>
567 __attribute__((__always_inline__))
568 static _Setter<_Res, __exception_ptr_tag>
569 __setter(exception_ptr& __ex, promise<_Res>* __prom) noexcept
571 __glibcxx_assert(__ex != nullptr); // LWG 2276
572 return _Setter<_Res, __exception_ptr_tag>{ __prom, &__ex };
575 template<typename _Res>
576 __attribute__((__always_inline__))
577 static _Setter<_Res, void>
578 __setter(promise<_Res>* __prom) noexcept
580 return _Setter<_Res, void>{ __prom };
583 template<typename _Tp>
585 _S_check(const shared_ptr<_Tp>& __p)
587 if (!static_cast<bool>(__p))
588 __throw_future_error((int)future_errc::no_state);
592 // The function invoked with std::call_once(_M_once, ...).
594 _M_do_set(function<_Ptr_type()>* __f, bool* __did_set)
596 _Ptr_type __res = (*__f)();
597 // Notify the caller that we did try to set; if we do not throw an
598 // exception, the caller will be aware that it did set (e.g., see
601 _M_result.swap(__res); // nothrow
604 // Wait for completion of async function.
605 virtual void _M_complete_async() { }
607 // Return true if state corresponds to a deferred function.
608 virtual bool _M_is_deferred_future() const { return false; }
610 struct _Make_ready final : __at_thread_exit_elt
612 weak_ptr<_State_baseV2> _M_shared_state;
613 static void _S_run(void*);
618#ifdef _GLIBCXX_ASYNC_ABI_COMPAT
620 class _Async_state_common;
622 using _State_base = _State_baseV2;
623 class _Async_state_commonV2;
626 template<typename _BoundFn,
627 typename _Res = decltype(std::declval<_BoundFn&>()())>
628 class _Deferred_state;
630 template<typename _BoundFn,
631 typename _Res = decltype(std::declval<_BoundFn&>()())>
632 class _Async_state_impl;
634 template<typename _Signature>
635 struct _Task_state_base;
637 template<typename _Fn, typename _Alloc, typename _Signature>
640 template<typename _Res_ptr, typename _Fn,
641 typename _Res = typename _Res_ptr::element_type::result_type>
644 template<typename _Res_ptr, typename _BoundFn>
645 static _Task_setter<_Res_ptr, _BoundFn>
646 _S_task_setter(_Res_ptr& __ptr, _BoundFn& __call)
648 return { std::__addressof(__ptr), std::__addressof(__call) };
652 /// Partial specialization for reference types.
653 template<typename _Res>
654 struct __future_base::_Result<_Res&> : __future_base::_Result_base
656 typedef _Res& result_type;
658 _Result() noexcept : _M_value_ptr() { }
661 _M_set(_Res& __res) noexcept
662 { _M_value_ptr = std::addressof(__res); }
664 _Res& _M_get() noexcept { return *_M_value_ptr; }
669 void _M_destroy() { delete this; }
672 /// Explicit specialization for void.
674 struct __future_base::_Result<void> : __future_base::_Result_base
676 typedef void result_type;
679 void _M_destroy() { delete this; }
684#ifndef _GLIBCXX_ASYNC_ABI_COMPAT
686 /// @cond undocumented
687 // Allow _Setter objects to be stored locally in std::function
688 template<typename _Res, typename _Arg>
689 struct __is_location_invariant
690 <__future_base::_State_base::_Setter<_Res, _Arg>>
693 // Allow _Task_setter objects to be stored locally in std::function
694 template<typename _Res_ptr, typename _Fn, typename _Res>
695 struct __is_location_invariant
696 <__future_base::_Task_setter<_Res_ptr, _Fn, _Res>>
700 /// Common implementation for future and shared_future.
701 template<typename _Res>
702 class __basic_future : public __future_base
705 typedef shared_ptr<_State_base> __state_type;
706 typedef __future_base::_Result<_Res>& __result_type;
709 __state_type _M_state;
713 __basic_future(const __basic_future&) = delete;
714 __basic_future& operator=(const __basic_future&) = delete;
717 valid() const noexcept { return static_cast<bool>(_M_state); }
722 _State_base::_S_check(_M_state);
726 template<typename _Rep, typename _Period>
728 wait_for(const chrono::duration<_Rep, _Period>& __rel) const
730 _State_base::_S_check(_M_state);
731 return _M_state->wait_for(__rel);
734 template<typename _Clock, typename _Duration>
736 wait_until(const chrono::time_point<_Clock, _Duration>& __abs) const
738 _State_base::_S_check(_M_state);
739 return _M_state->wait_until(__abs);
743 /// Wait for the state to be ready and rethrow any stored exception
745 _M_get_result() const
747 _State_base::_S_check(_M_state);
748 _Result_base& __res = _M_state->wait();
749 if (!(__res._M_error == nullptr))
750 rethrow_exception(__res._M_error);
751 return static_cast<__result_type>(__res);
754 void _M_swap(__basic_future& __that) noexcept
756 _M_state.swap(__that._M_state);
759 // Construction of a future by promise::get_future()
761 __basic_future(const __state_type& __state) : _M_state(__state)
763 _State_base::_S_check(_M_state);
764 _M_state->_M_set_retrieved_flag();
767 // Copy construction from a shared_future
769 __basic_future(const shared_future<_Res>&) noexcept;
771 // Move construction from a shared_future
773 __basic_future(shared_future<_Res>&&) noexcept;
775 // Move construction from a future
777 __basic_future(future<_Res>&&) noexcept;
779 constexpr __basic_future() noexcept : _M_state() { }
783 explicit _Reset(__basic_future& __fut) noexcept : _M_fut(__fut) { }
784 ~_Reset() { _M_fut._M_state.reset(); }
785 __basic_future& _M_fut;
790 /// Primary template for future.
791 template<typename _Res>
792 class future : public __basic_future<_Res>
794 // _GLIBCXX_RESOLVE_LIB_DEFECTS
795 // 3458. Is shared_future intended to work with arrays or function types?
796 static_assert(!is_array<_Res>{}, "result type must not be an array");
797 static_assert(!is_function<_Res>{}, "result type must not be a function");
798 static_assert(is_destructible<_Res>{},
799 "result type must be destructible");
801 friend class promise<_Res>;
802 template<typename> friend class packaged_task;
803 template<typename _Fn, typename... _Args>
804 friend future<__async_result_of<_Fn, _Args...>>
805 async(launch, _Fn&&, _Args&&...);
807 typedef __basic_future<_Res> _Base_type;
808 typedef typename _Base_type::__state_type __state_type;
811 future(const __state_type& __state) : _Base_type(__state) { }
814 constexpr future() noexcept : _Base_type() { }
817 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { }
820 future(const future&) = delete;
821 future& operator=(const future&) = delete;
823 future& operator=(future&& __fut) noexcept
825 future(std::move(__fut))._M_swap(*this);
829 /// Retrieving the value
833 typename _Base_type::_Reset __reset(*this);
834 return std::move(this->_M_get_result()._M_value());
837 shared_future<_Res> share() noexcept;
840 /// Partial specialization for future<R&>
841 template<typename _Res>
842 class future<_Res&> : public __basic_future<_Res&>
844 friend class promise<_Res&>;
845 template<typename> friend class packaged_task;
846 template<typename _Fn, typename... _Args>
847 friend future<__async_result_of<_Fn, _Args...>>
848 async(launch, _Fn&&, _Args&&...);
850 typedef __basic_future<_Res&> _Base_type;
851 typedef typename _Base_type::__state_type __state_type;
854 future(const __state_type& __state) : _Base_type(__state) { }
857 constexpr future() noexcept : _Base_type() { }
860 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { }
863 future(const future&) = delete;
864 future& operator=(const future&) = delete;
866 future& operator=(future&& __fut) noexcept
868 future(std::move(__fut))._M_swap(*this);
872 /// Retrieving the value
876 typename _Base_type::_Reset __reset(*this);
877 return this->_M_get_result()._M_get();
880 shared_future<_Res&> share() noexcept;
883 /// Explicit specialization for future<void>
885 class future<void> : public __basic_future<void>
887 friend class promise<void>;
888 template<typename> friend class packaged_task;
889 template<typename _Fn, typename... _Args>
890 friend future<__async_result_of<_Fn, _Args...>>
891 async(launch, _Fn&&, _Args&&...);
893 typedef __basic_future<void> _Base_type;
894 typedef typename _Base_type::__state_type __state_type;
897 future(const __state_type& __state) : _Base_type(__state) { }
900 constexpr future() noexcept : _Base_type() { }
903 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { }
906 future(const future&) = delete;
907 future& operator=(const future&) = delete;
909 future& operator=(future&& __fut) noexcept
911 future(std::move(__fut))._M_swap(*this);
915 /// Retrieving the value
919 typename _Base_type::_Reset __reset(*this);
920 this->_M_get_result();
923 shared_future<void> share() noexcept;
927 /// Primary template for shared_future.
928 template<typename _Res>
929 class shared_future : public __basic_future<_Res>
931 // _GLIBCXX_RESOLVE_LIB_DEFECTS
932 // 3458. Is shared_future intended to work with arrays or function types?
933 static_assert(!is_array<_Res>{}, "result type must not be an array");
934 static_assert(!is_function<_Res>{}, "result type must not be a function");
935 static_assert(is_destructible<_Res>{},
936 "result type must be destructible");
938 typedef __basic_future<_Res> _Base_type;
941 constexpr shared_future() noexcept : _Base_type() { }
944 shared_future(const shared_future& __sf) noexcept : _Base_type(__sf) { }
946 /// Construct from a future rvalue
947 shared_future(future<_Res>&& __uf) noexcept
948 : _Base_type(std::move(__uf))
951 /// Construct from a shared_future rvalue
952 shared_future(shared_future&& __sf) noexcept
953 : _Base_type(std::move(__sf))
956 shared_future& operator=(const shared_future& __sf) noexcept
958 shared_future(__sf)._M_swap(*this);
962 shared_future& operator=(shared_future&& __sf) noexcept
964 shared_future(std::move(__sf))._M_swap(*this);
968 /// Retrieving the value
970 get() const { return this->_M_get_result()._M_value(); }
973 /// Partial specialization for shared_future<R&>
974 template<typename _Res>
975 class shared_future<_Res&> : public __basic_future<_Res&>
977 typedef __basic_future<_Res&> _Base_type;
980 constexpr shared_future() noexcept : _Base_type() { }
983 shared_future(const shared_future& __sf) : _Base_type(__sf) { }
985 /// Construct from a future rvalue
986 shared_future(future<_Res&>&& __uf) noexcept
987 : _Base_type(std::move(__uf))
990 /// Construct from a shared_future rvalue
991 shared_future(shared_future&& __sf) noexcept
992 : _Base_type(std::move(__sf))
995 shared_future& operator=(const shared_future& __sf)
997 shared_future(__sf)._M_swap(*this);
1001 shared_future& operator=(shared_future&& __sf) noexcept
1003 shared_future(std::move(__sf))._M_swap(*this);
1007 /// Retrieving the value
1009 get() const { return this->_M_get_result()._M_get(); }
1012 /// Explicit specialization for shared_future<void>
1014 class shared_future<void> : public __basic_future<void>
1016 typedef __basic_future<void> _Base_type;
1019 constexpr shared_future() noexcept : _Base_type() { }
1021 /// Copy constructor
1022 shared_future(const shared_future& __sf) : _Base_type(__sf) { }
1024 /// Construct from a future rvalue
1025 shared_future(future<void>&& __uf) noexcept
1026 : _Base_type(std::move(__uf))
1029 /// Construct from a shared_future rvalue
1030 shared_future(shared_future&& __sf) noexcept
1031 : _Base_type(std::move(__sf))
1034 shared_future& operator=(const shared_future& __sf)
1036 shared_future(__sf)._M_swap(*this);
1040 shared_future& operator=(shared_future&& __sf) noexcept
1042 shared_future(std::move(__sf))._M_swap(*this);
1046 // Retrieving the value
1048 get() const { this->_M_get_result(); }
1051 // Now we can define the protected __basic_future constructors.
1052 template<typename _Res>
1053 inline __basic_future<_Res>::
1054 __basic_future(const shared_future<_Res>& __sf) noexcept
1055 : _M_state(__sf._M_state)
1058 template<typename _Res>
1059 inline __basic_future<_Res>::
1060 __basic_future(shared_future<_Res>&& __sf) noexcept
1061 : _M_state(std::move(__sf._M_state))
1064 template<typename _Res>
1065 inline __basic_future<_Res>::
1066 __basic_future(future<_Res>&& __uf) noexcept
1067 : _M_state(std::move(__uf._M_state))
1070 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1071 // 2556. Wide contract for future::share()
1072 template<typename _Res>
1073 inline shared_future<_Res>
1074 future<_Res>::share() noexcept
1075 { return shared_future<_Res>(std::move(*this)); }
1077 template<typename _Res>
1078 inline shared_future<_Res&>
1079 future<_Res&>::share() noexcept
1080 { return shared_future<_Res&>(std::move(*this)); }
1082 inline shared_future<void>
1083 future<void>::share() noexcept
1084 { return shared_future<void>(std::move(*this)); }
1086 /// Primary template for promise
1087 template<typename _Res>
1090 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1091 // 3466: Specify the requirements for promise/future/[...] consistently
1092 static_assert(!is_array<_Res>{}, "result type must not be an array");
1093 static_assert(!is_function<_Res>{}, "result type must not be a function");
1094 static_assert(is_destructible<_Res>{},
1095 "result type must be destructible");
1097 typedef __future_base::_State_base _State;
1098 typedef __future_base::_Result<_Res> _Res_type;
1099 typedef __future_base::_Ptr<_Res_type> _Ptr_type;
1100 template<typename, typename> friend struct _State::_Setter;
1103 shared_ptr<_State> _M_future;
1104 _Ptr_type _M_storage;
1108 : _M_future(std::make_shared<_State>()),
1109 _M_storage(new _Res_type())
1112 promise(promise&& __rhs) noexcept
1113 : _M_future(std::move(__rhs._M_future)),
1114 _M_storage(std::move(__rhs._M_storage))
1117 template<typename _Allocator>
1118 promise(allocator_arg_t, const _Allocator& __a)
1119 : _M_future(std::allocate_shared<_State>(__a)),
1120 _M_storage(__future_base::_S_allocate_result<_Res>(__a))
1123 template<typename _Allocator>
1124 promise(allocator_arg_t, const _Allocator&, promise&& __rhs)
1125 : _M_future(std::move(__rhs._M_future)),
1126 _M_storage(std::move(__rhs._M_storage))
1129 promise(const promise&) = delete;
1133 if (static_cast<bool>(_M_future) && !_M_future.unique())
1134 _M_future->_M_break_promise(std::move(_M_storage));
1139 operator=(promise&& __rhs) noexcept
1141 promise(std::move(__rhs)).swap(*this);
1145 promise& operator=(const promise&) = delete;
1148 swap(promise& __rhs) noexcept
1150 _M_future.swap(__rhs._M_future);
1151 _M_storage.swap(__rhs._M_storage);
1154 // Retrieving the result
1157 { return future<_Res>(_M_future); }
1159 // Setting the result
1161 set_value(const _Res& __r)
1162 { _M_state()._M_set_result(_State::__setter(this, __r)); }
1165 set_value(_Res&& __r)
1166 { _M_state()._M_set_result(_State::__setter(this, std::move(__r))); }
1169 set_exception(exception_ptr __p)
1170 { _M_state()._M_set_result(_State::__setter(__p, this)); }
1173 set_value_at_thread_exit(const _Res& __r)
1175 _M_state()._M_set_delayed_result(_State::__setter(this, __r),
1180 set_value_at_thread_exit(_Res&& __r)
1182 _M_state()._M_set_delayed_result(
1183 _State::__setter(this, std::move(__r)), _M_future);
1187 set_exception_at_thread_exit(exception_ptr __p)
1189 _M_state()._M_set_delayed_result(_State::__setter(__p, this),
1197 __future_base::_State_base::_S_check(_M_future);
1202 template<typename _Res>
1204 swap(promise<_Res>& __x, promise<_Res>& __y) noexcept
1207 template<typename _Res, typename _Alloc>
1208 struct uses_allocator<promise<_Res>, _Alloc>
1209 : public true_type { };
1212 /// Partial specialization for promise<R&>
1213 template<typename _Res>
1214 class promise<_Res&>
1216 typedef __future_base::_State_base _State;
1217 typedef __future_base::_Result<_Res&> _Res_type;
1218 typedef __future_base::_Ptr<_Res_type> _Ptr_type;
1219 template<typename, typename> friend struct _State::_Setter;
1222 shared_ptr<_State> _M_future;
1223 _Ptr_type _M_storage;
1227 : _M_future(std::make_shared<_State>()),
1228 _M_storage(new _Res_type())
1231 promise(promise&& __rhs) noexcept
1232 : _M_future(std::move(__rhs._M_future)),
1233 _M_storage(std::move(__rhs._M_storage))
1236 template<typename _Allocator>
1237 promise(allocator_arg_t, const _Allocator& __a)
1238 : _M_future(std::allocate_shared<_State>(__a)),
1239 _M_storage(__future_base::_S_allocate_result<_Res&>(__a))
1242 template<typename _Allocator>
1243 promise(allocator_arg_t, const _Allocator&, promise&& __rhs)
1244 : _M_future(std::move(__rhs._M_future)),
1245 _M_storage(std::move(__rhs._M_storage))
1248 promise(const promise&) = delete;
1252 if (static_cast<bool>(_M_future) && !_M_future.unique())
1253 _M_future->_M_break_promise(std::move(_M_storage));
1258 operator=(promise&& __rhs) noexcept
1260 promise(std::move(__rhs)).swap(*this);
1264 promise& operator=(const promise&) = delete;
1267 swap(promise& __rhs) noexcept
1269 _M_future.swap(__rhs._M_future);
1270 _M_storage.swap(__rhs._M_storage);
1273 // Retrieving the result
1276 { return future<_Res&>(_M_future); }
1278 // Setting the result
1280 set_value(_Res& __r)
1281 { _M_state()._M_set_result(_State::__setter(this, __r)); }
1284 set_exception(exception_ptr __p)
1285 { _M_state()._M_set_result(_State::__setter(__p, this)); }
1288 set_value_at_thread_exit(_Res& __r)
1290 _M_state()._M_set_delayed_result(_State::__setter(this, __r),
1295 set_exception_at_thread_exit(exception_ptr __p)
1297 _M_state()._M_set_delayed_result(_State::__setter(__p, this),
1305 __future_base::_State_base::_S_check(_M_future);
1310 /// Explicit specialization for promise<void>
1314 typedef __future_base::_State_base _State;
1315 typedef __future_base::_Result<void> _Res_type;
1316 typedef __future_base::_Ptr<_Res_type> _Ptr_type;
1317 template<typename, typename> friend struct _State::_Setter;
1320 shared_ptr<_State> _M_future;
1321 _Ptr_type _M_storage;
1325 : _M_future(std::make_shared<_State>()),
1326 _M_storage(new _Res_type())
1329 promise(promise&& __rhs) noexcept
1330 : _M_future(std::move(__rhs._M_future)),
1331 _M_storage(std::move(__rhs._M_storage))
1334 template<typename _Allocator>
1335 promise(allocator_arg_t, const _Allocator& __a)
1336 : _M_future(std::allocate_shared<_State>(__a)),
1337 _M_storage(__future_base::_S_allocate_result<void>(__a))
1340 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1341 // 2095. missing constructors needed for uses-allocator construction
1342 template<typename _Allocator>
1343 promise(allocator_arg_t, const _Allocator&, promise&& __rhs)
1344 : _M_future(std::move(__rhs._M_future)),
1345 _M_storage(std::move(__rhs._M_storage))
1348 promise(const promise&) = delete;
1352 if (static_cast<bool>(_M_future) && !_M_future.unique())
1353 _M_future->_M_break_promise(std::move(_M_storage));
1358 operator=(promise&& __rhs) noexcept
1360 promise(std::move(__rhs)).swap(*this);
1364 promise& operator=(const promise&) = delete;
1367 swap(promise& __rhs) noexcept
1369 _M_future.swap(__rhs._M_future);
1370 _M_storage.swap(__rhs._M_storage);
1373 // Retrieving the result
1376 { return future<void>(_M_future); }
1378 // Setting the result
1381 { _M_state()._M_set_result(_State::__setter(this)); }
1384 set_exception(exception_ptr __p)
1385 { _M_state()._M_set_result(_State::__setter(__p, this)); }
1388 set_value_at_thread_exit()
1389 { _M_state()._M_set_delayed_result(_State::__setter(this), _M_future); }
1392 set_exception_at_thread_exit(exception_ptr __p)
1394 _M_state()._M_set_delayed_result(_State::__setter(__p, this),
1402 __future_base::_State_base::_S_check(_M_future);
1407 /// @cond undocumented
1408 template<typename _Ptr_type, typename _Fn, typename _Res>
1409 struct __future_base::_Task_setter
1411 // Invoke the function and provide the result to the caller.
1412 _Ptr_type operator()() const
1416 (*_M_result)->_M_set((*_M_fn)());
1418 __catch(const __cxxabiv1::__forced_unwind&)
1420 __throw_exception_again; // will cause broken_promise
1424 (*_M_result)->_M_error = current_exception();
1426 return std::move(*_M_result);
1428 _Ptr_type* _M_result;
1432 template<typename _Ptr_type, typename _Fn>
1433 struct __future_base::_Task_setter<_Ptr_type, _Fn, void>
1435 _Ptr_type operator()() const
1441 __catch(const __cxxabiv1::__forced_unwind&)
1443 __throw_exception_again; // will cause broken_promise
1447 (*_M_result)->_M_error = current_exception();
1449 return std::move(*_M_result);
1451 _Ptr_type* _M_result;
1455 // Holds storage for a packaged_task's result.
1456 template<typename _Res, typename... _Args>
1457 struct __future_base::_Task_state_base<_Res(_Args...)>
1458 : __future_base::_State_base
1460 typedef _Res _Res_type;
1462 template<typename _Alloc>
1463 _Task_state_base(const _Alloc& __a)
1464 : _M_result(_S_allocate_result<_Res>(__a))
1467 // Invoke the stored task and make the state ready.
1469 _M_run(_Args&&... __args) = 0;
1471 // Invoke the stored task and make the state ready at thread exit.
1473 _M_run_delayed(_Args&&... __args, weak_ptr<_State_base>) = 0;
1475 virtual shared_ptr<_Task_state_base>
1478 typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type;
1479 _Ptr_type _M_result;
1482 // Holds a packaged_task's stored task.
1483 template<typename _Fn, typename _Alloc, typename _Res, typename... _Args>
1484 struct __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)> final
1485 : __future_base::_Task_state_base<_Res(_Args...)>
1487 template<typename _Fn2>
1488 _Task_state(_Fn2&& __fn, const _Alloc& __a)
1489 : _Task_state_base<_Res(_Args...)>(__a),
1490 _M_impl(std::forward<_Fn2>(__fn), __a)
1495 _M_run(_Args&&... __args)
1497 auto __boundfn = [&] () -> _Res {
1498 return std::__invoke_r<_Res>(_M_impl._M_fn,
1499 std::forward<_Args>(__args)...);
1501 this->_M_set_result(_S_task_setter(this->_M_result, __boundfn));
1505 _M_run_delayed(_Args&&... __args, weak_ptr<_State_base> __self)
1507 auto __boundfn = [&] () -> _Res {
1508 return std::__invoke_r<_Res>(_M_impl._M_fn,
1509 std::forward<_Args>(__args)...);
1511 this->_M_set_delayed_result(_S_task_setter(this->_M_result, __boundfn),
1515 virtual shared_ptr<_Task_state_base<_Res(_Args...)>>
1518 struct _Impl : _Alloc
1520 template<typename _Fn2>
1521 _Impl(_Fn2&& __fn, const _Alloc& __a)
1522 : _Alloc(__a), _M_fn(std::forward<_Fn2>(__fn)) { }
1527 template<typename _Signature, typename _Fn,
1528 typename _Alloc = std::allocator<int>>
1529 static shared_ptr<__future_base::_Task_state_base<_Signature>>
1530 __create_task_state(_Fn&& __fn, const _Alloc& __a = _Alloc())
1532 typedef typename decay<_Fn>::type _Fn2;
1533 typedef __future_base::_Task_state<_Fn2, _Alloc, _Signature> _State;
1534 return std::allocate_shared<_State>(__a, std::forward<_Fn>(__fn), __a);
1537 template<typename _Fn, typename _Alloc, typename _Res, typename... _Args>
1538 shared_ptr<__future_base::_Task_state_base<_Res(_Args...)>>
1539 __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)>::_M_reset()
1541 return __create_task_state<_Res(_Args...)>(std::move(_M_impl._M_fn),
1542 static_cast<_Alloc&>(_M_impl));
1547 template<typename _Res, typename... _ArgTypes>
1548 class packaged_task<_Res(_ArgTypes...)>
1550 typedef __future_base::_Task_state_base<_Res(_ArgTypes...)> _State_type;
1551 shared_ptr<_State_type> _M_state;
1553 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1554 // 3039. Unnecessary decay in thread and packaged_task
1555 template<typename _Fn, typename _Fn2 = __remove_cvref_t<_Fn>>
1557 = typename enable_if<!is_same<packaged_task, _Fn2>::value>::type;
1560 // Construction and destruction
1561 packaged_task() noexcept { }
1563 template<typename _Fn, typename = __not_same<_Fn>>
1565 packaged_task(_Fn&& __fn)
1567 __create_task_state<_Res(_ArgTypes...)>(std::forward<_Fn>(__fn)))
1569#ifdef __cpp_lib_is_invocable // C++ >= 17
1570 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1571 // 4154. The Mandates for std::packaged_task's constructor
1572 // from a callable entity should consider decaying
1573 static_assert(is_invocable_r_v<_Res, decay_t<_Fn>&, _ArgTypes...>);
1577#if __cplusplus < 201703L
1578 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1579 // 2097. packaged_task constructors should be constrained
1580 // 2407. [this constructor should not be] explicit
1581 // 2921. packaged_task and type-erased allocators
1582 template<typename _Fn, typename _Alloc, typename = __not_same<_Fn>>
1583 packaged_task(allocator_arg_t, const _Alloc& __a, _Fn&& __fn)
1584 : _M_state(__create_task_state<_Res(_ArgTypes...)>(
1585 std::forward<_Fn>(__fn), __a))
1588 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1589 // 2095. missing constructors needed for uses-allocator construction
1590 template<typename _Allocator>
1591 packaged_task(allocator_arg_t, const _Allocator&) noexcept
1594 template<typename _Allocator>
1595 packaged_task(allocator_arg_t, const _Allocator&,
1596 const packaged_task&) = delete;
1598 template<typename _Allocator>
1599 packaged_task(allocator_arg_t, const _Allocator&,
1600 packaged_task&& __other) noexcept
1601 { this->swap(__other); }
1606 if (static_cast<bool>(_M_state) && !_M_state.unique())
1607 _M_state->_M_break_promise(std::move(_M_state->_M_result));
1611 packaged_task(const packaged_task&) = delete;
1612 packaged_task& operator=(const packaged_task&) = delete;
1615 packaged_task(packaged_task&& __other) noexcept
1616 { this->swap(__other); }
1618 packaged_task& operator=(packaged_task&& __other) noexcept
1620 packaged_task(std::move(__other)).swap(*this);
1625 swap(packaged_task& __other) noexcept
1626 { _M_state.swap(__other._M_state); }
1629 valid() const noexcept
1630 { return static_cast<bool>(_M_state); }
1635 { return future<_Res>(_M_state); }
1639 operator()(_ArgTypes... __args)
1641 __future_base::_State_base::_S_check(_M_state);
1642 _M_state->_M_run(std::forward<_ArgTypes>(__args)...);
1646 make_ready_at_thread_exit(_ArgTypes... __args)
1648 __future_base::_State_base::_S_check(_M_state);
1649 _M_state->_M_run_delayed(std::forward<_ArgTypes>(__args)..., _M_state);
1655 __future_base::_State_base::_S_check(_M_state);
1656 packaged_task __tmp;
1657 __tmp._M_state = _M_state;
1658 _M_state = _M_state->_M_reset();
1662 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1663 // 3117. Missing packaged_task deduction guides
1664#if __cpp_deduction_guides >= 201606
1665 template<typename _Res, typename... _ArgTypes>
1666 packaged_task(_Res(*)(_ArgTypes...)) -> packaged_task<_Res(_ArgTypes...)>;
1668 template<typename _Fun, typename _Signature
1669 = __function_guide_t<_Fun, decltype(&_Fun::operator())>>
1670 packaged_task(_Fun) -> packaged_task<_Signature>;
1674 template<typename _Res, typename... _ArgTypes>
1676 swap(packaged_task<_Res(_ArgTypes...)>& __x,
1677 packaged_task<_Res(_ArgTypes...)>& __y) noexcept
1680#if __cplusplus < 201703L
1681 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1682 // 2976. Dangling uses_allocator specialization for packaged_task
1683 template<typename _Res, typename _Alloc>
1684 struct uses_allocator<packaged_task<_Res>, _Alloc>
1685 : public true_type { };
1688 /// @cond undocumented
1690 // Shared state created by std::async().
1691 // Holds a deferred function and storage for its result.
1692 template<typename _BoundFn, typename _Res>
1693 class __future_base::_Deferred_state final
1694 : public __future_base::_State_base
1697 template<typename... _Args>
1699 _Deferred_state(_Args&&... __args)
1700 : _M_result(new _Result<_Res>()),
1701 _M_fn(std::forward<_Args>(__args)...)
1705 typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type;
1706 _Ptr_type _M_result;
1709 // Run the deferred function.
1713 // Multiple threads can call a waiting function on the future and
1714 // reach this point at the same time. The call_once in _M_set_result
1715 // ensures only the first one run the deferred function, stores the
1716 // result in _M_result, swaps that with the base _M_result and makes
1717 // the state ready. Tell _M_set_result to ignore failure so all later
1718 // calls do nothing.
1719 _M_set_result(_S_task_setter(_M_result, _M_fn), true);
1722 // Caller should check whether the state is ready first, because this
1723 // function will return true even after the deferred function has run.
1724 virtual bool _M_is_deferred_future() const { return true; }
1727 // Common functionality hoisted out of the _Async_state_impl template.
1728 class __future_base::_Async_state_commonV2
1729 : public __future_base::_State_base
1732 ~_Async_state_commonV2() = default;
1734 // Make waiting functions block until the thread completes, as if joined.
1736 // This function is used by wait() to satisfy the first requirement below
1737 // and by wait_for() / wait_until() to satisfy the second.
1741 // - a call to a waiting function on an asynchronous return object that
1742 // shares the shared state created by this async call shall block until
1743 // the associated thread has completed, as if joined, or else time out.
1745 // - the associated thread completion synchronizes with the return from
1746 // the first function that successfully detects the ready status of the
1747 // shared state or with the return from the last function that releases
1748 // the shared state, whichever happens first.
1749 virtual void _M_complete_async() { _M_join(); }
1751 void _M_join() { std::call_once(_M_once, &thread::join, &_M_thread); }
1757 // Shared state created by std::async().
1758 // Starts a new thread that runs a function and makes the shared state ready.
1759 template<typename _BoundFn, typename _Res>
1760 class __future_base::_Async_state_impl final
1761 : public __future_base::_Async_state_commonV2
1764 template<typename... _Args>
1766 _Async_state_impl(_Args&&... __args)
1767 : _M_result(new _Result<_Res>()),
1768 _M_fn(std::forward<_Args>(__args)...)
1770 _M_thread = std::thread{&_Async_state_impl::_M_run, this};
1773 // Must not destroy _M_result and _M_fn until the thread finishes.
1774 // Call join() directly rather than through _M_join() because no other
1775 // thread can be referring to this state if it is being destroyed.
1776 ~_Async_state_impl()
1778 if (_M_thread.joinable())
1788 _M_set_result(_S_task_setter(_M_result, _M_fn));
1790 __catch (const __cxxabiv1::__forced_unwind&)
1792 // make the shared state ready on thread cancellation
1793 if (static_cast<bool>(_M_result))
1794 this->_M_break_promise(std::move(_M_result));
1795 __throw_exception_again;
1799 typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type;
1800 _Ptr_type _M_result;
1806 template<typename _Fn, typename... _Args>
1807 _GLIBCXX_NODISCARD future<__async_result_of<_Fn, _Args...>>
1808 async(launch __policy, _Fn&& __fn, _Args&&... __args)
1810 using _Wr = std::thread::_Call_wrapper<_Fn, _Args...>;
1811 using _As = __future_base::_Async_state_impl<_Wr>;
1812 using _Ds = __future_base::_Deferred_state<_Wr>;
1814 std::shared_ptr<__future_base::_State_base> __state;
1815 if ((__policy & launch::async) == launch::async)
1819 __state = std::make_shared<_As>(std::forward<_Fn>(__fn),
1820 std::forward<_Args>(__args)...);
1823 catch(const system_error& __e)
1825 if (__e.code() != errc::resource_unavailable_try_again
1826 || (__policy & launch::deferred) != launch::deferred)
1833 __state = std::make_shared<_Ds>(std::forward<_Fn>(__fn),
1834 std::forward<_Args>(__args)...);
1836 return future<__async_result_of<_Fn, _Args...>>(std::move(__state));
1839 /// async, potential overload
1840 template<typename _Fn, typename... _Args>
1841 _GLIBCXX_NODISCARD inline future<__async_result_of<_Fn, _Args...>>
1842 async(_Fn&& __fn, _Args&&... __args)
1844 return std::async(launch::async|launch::deferred,
1845 std::forward<_Fn>(__fn),
1846 std::forward<_Args>(__args)...);
1849#endif // _GLIBCXX_ASYNC_ABI_COMPAT
1850#endif // _GLIBCXX_HAS_GTHREADS
1852 /// @} group futures
1853_GLIBCXX_END_NAMESPACE_VERSION
1858#endif // _GLIBCXX_FUTURE