1 // <future> -*- C++ -*-
3 // Copyright (C) 2009-2025 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 #ifdef _GLIBCXX_SYSHDR
33 #pragma GCC system_header
36 #include <bits/requires_hosted.h> // concurrency
38 #if __cplusplus < 201103L
39 # include <bits/c++0x_warning.h>
42 #include <mutex> // call_once
43 #include <condition_variable> // __at_thread_exit_elt
44 #include <system_error>
45 #include <bits/atomic_base.h> // atomic_flag
46 #include <bits/allocated_ptr.h>
47 #include <bits/atomic_futex.h>
48 #include <bits/exception_defines.h>
49 #include <bits/invoke.h>
50 #include <bits/unique_ptr.h>
51 #include <bits/shared_ptr.h>
52 #include <bits/std_function.h>
53 #include <bits/std_thread.h>
54 #include <bits/uses_allocator.h>
55 #include <ext/aligned_buffer.h>
57 namespace std _GLIBCXX_VISIBILITY(default)
59 _GLIBCXX_BEGIN_NAMESPACE_VERSION
62 * @defgroup futures Futures
63 * @ingroup concurrency
65 * Futures and promises provide support for retrieving the result from
66 * an asynchronous function, e.g. one that is running in another thread.
67 * A `std::future` represents an asynchronous result that will become
68 * ready at some later time. A consumer can wait on a future until the
69 * result is ready to be accessed.
75 /// Error code for futures
76 enum class future_errc
78 future_already_retrieved = 1,
79 promise_already_satisfied,
84 /// Specialization that allows `future_errc` to convert to `error_code`.
86 struct is_error_code_enum<future_errc> : public true_type { };
88 /// Points to a statically-allocated object derived from error_category.
89 [[__nodiscard__, __gnu__::__const__]]
91 future_category() noexcept;
93 /// Overload of make_error_code for `future_errc`.
96 make_error_code(future_errc __errc) noexcept
97 { return error_code(static_cast<int>(__errc), future_category()); }
99 /// Overload of make_error_condition for `future_errc`.
101 inline error_condition
102 make_error_condition(future_errc __errc) noexcept
103 { return error_condition(static_cast<int>(__errc), future_category()); }
106 * @brief Exception type thrown by futures.
107 * @ingroup exceptions
110 class future_error : public logic_error
114 future_error(future_errc __errc)
115 : future_error(std::make_error_code(__errc))
118 virtual ~future_error() noexcept;
121 what() const noexcept;
124 code() const noexcept { return _M_code; }
128 future_error(error_code __ec)
129 : logic_error("std::future_error: " + __ec.message()), _M_code(__ec)
132 friend void __throw_future_error(int);
137 // Forward declarations.
138 template<typename _Res>
141 template<typename _Res>
144 template<typename _Signature>
147 template<typename _Res>
150 /// Launch code for futures
158 constexpr launch operator&(launch __x, launch __y) noexcept
160 return static_cast<launch>(
161 static_cast<int>(__x) & static_cast<int>(__y));
165 constexpr launch operator|(launch __x, launch __y) noexcept
167 return static_cast<launch>(
168 static_cast<int>(__x) | static_cast<int>(__y));
172 constexpr launch operator^(launch __x, launch __y) noexcept
174 return static_cast<launch>(
175 static_cast<int>(__x) ^ static_cast<int>(__y));
179 constexpr launch operator~(launch __x) noexcept
180 { return static_cast<launch>(~static_cast<int>(__x)); }
183 inline launch& operator&=(launch& __x, launch __y) noexcept
184 { return __x = __x & __y; }
187 inline launch& operator|=(launch& __x, launch __y) noexcept
188 { return __x = __x | __y; }
191 inline launch& operator^=(launch& __x, launch __y) noexcept
192 { return __x = __x ^ __y; }
194 /// Status code for futures
195 enum class future_status
202 /// @cond undocumented
203 // _GLIBCXX_RESOLVE_LIB_DEFECTS
204 // 2021. Further incorrect usages of result_of
205 template<typename _Fn, typename... _Args>
206 using __async_result_of = typename __invoke_result<
207 typename decay<_Fn>::type, typename decay<_Args>::type...>::type;
210 template<typename _Fn, typename... _Args>
211 future<__async_result_of<_Fn, _Args...>>
212 async(launch __policy, _Fn&& __fn, _Args&&... __args);
214 template<typename _Fn, typename... _Args>
215 future<__async_result_of<_Fn, _Args...>>
216 async(_Fn&& __fn, _Args&&... __args);
218 #if defined(_GLIBCXX_HAS_GTHREADS)
220 /// @cond undocumented
222 /// Base class and enclosing scope.
225 /// Base class for results.
228 exception_ptr _M_error;
230 _Result_base(const _Result_base&) = delete;
231 _Result_base& operator=(const _Result_base&) = delete;
233 // _M_destroy() allows derived classes to control deallocation
234 virtual void _M_destroy() = 0;
238 void operator()(_Result_base* __fr) const { __fr->_M_destroy(); }
243 virtual ~_Result_base();
246 /// A unique_ptr for result objects.
247 template<typename _Res>
248 using _Ptr = unique_ptr<_Res, _Result_base::_Deleter>;
250 /// A result object that has storage for an object of type _Res.
251 template<typename _Res>
252 struct _Result : _Result_base
255 __gnu_cxx::__aligned_buffer<_Res> _M_storage;
259 typedef _Res result_type;
261 _Result() noexcept : _M_initialized() { }
269 // Return lvalue, future will add const or rvalue-reference
271 _M_value() noexcept { return *_M_storage._M_ptr(); }
274 _M_set(const _Res& __res)
276 ::new (_M_storage._M_addr()) _Res(__res);
277 _M_initialized = true;
283 ::new (_M_storage._M_addr()) _Res(std::move(__res));
284 _M_initialized = true;
288 void _M_destroy() { delete this; }
291 /// A result object that uses an allocator.
292 template<typename _Res, typename _Alloc>
293 struct _Result_alloc final : _Result<_Res>, _Alloc
295 using __allocator_type = __alloc_rebind<_Alloc, _Result_alloc>;
298 _Result_alloc(const _Alloc& __a) : _Result<_Res>(), _Alloc(__a)
304 __allocator_type __a(*this);
305 __allocated_ptr<__allocator_type> __guard_ptr{ __a, this };
306 this->~_Result_alloc();
310 // Create a result object that uses an allocator.
311 template<typename _Res, typename _Allocator>
312 static _Ptr<_Result_alloc<_Res, _Allocator>>
313 _S_allocate_result(const _Allocator& __a)
315 using __result_type = _Result_alloc<_Res, _Allocator>;
316 typename __result_type::__allocator_type __a2(__a);
317 auto __guard = std::__allocate_guarded(__a2);
318 __result_type* __p = ::new((void*)__guard.get()) __result_type{__a};
320 return _Ptr<__result_type>(__p);
323 // Keep it simple for std::allocator.
324 template<typename _Res, typename _Tp>
325 static _Ptr<_Result<_Res>>
326 _S_allocate_result(const std::allocator<_Tp>&)
328 return _Ptr<_Result<_Res>>(new _Result<_Res>);
331 // Base class for various types of shared state created by an
332 // asynchronous provider (such as a std::promise) and shared with one
333 // or more associated futures.
336 typedef _Ptr<_Result_base> _Ptr_type;
338 enum _Status : unsigned {
344 __atomic_futex_unsigned<> _M_status;
345 atomic_flag _M_retrieved = ATOMIC_FLAG_INIT;
349 _State_baseV2() noexcept : _M_result(), _M_status(_Status::__not_ready)
351 _State_baseV2(const _State_baseV2&) = delete;
352 _State_baseV2& operator=(const _State_baseV2&) = delete;
353 virtual ~_State_baseV2() = default;
358 // Run any deferred function or join any asynchronous thread:
360 // Acquire MO makes sure this synchronizes with the thread that made
362 _M_status._M_load_when_equal(_Status::__ready, memory_order_acquire);
366 template<typename _Rep, typename _Period>
368 wait_for(const chrono::duration<_Rep, _Period>& __rel)
370 // First, check if the future has been made ready. Use acquire MO
371 // to synchronize with the thread that made it ready.
372 if (_M_status._M_load(memory_order_acquire) == _Status::__ready)
373 return future_status::ready;
375 if (_M_is_deferred_future())
376 return future_status::deferred;
378 // Don't wait unless the relative time is greater than zero.
379 if (__rel > __rel.zero()
380 && _M_status._M_load_when_equal_for(_Status::__ready,
381 memory_order_acquire,
384 // _GLIBCXX_RESOLVE_LIB_DEFECTS
385 // 2100. timed waiting functions must also join
386 // This call is a no-op by default except on an async future,
387 // in which case the async thread is joined. It's also not a
388 // no-op for a deferred future, but such a future will never
389 // reach this point because it returns future_status::deferred
390 // instead of waiting for the future to become ready (see
391 // above). Async futures synchronize in this call, so we need
392 // no further synchronization here.
395 return future_status::ready;
397 return future_status::timeout;
400 template<typename _Clock, typename _Duration>
402 wait_until(const chrono::time_point<_Clock, _Duration>& __abs)
404 #if __cplusplus > 201703L
405 static_assert(chrono::is_clock_v<_Clock>);
407 // First, check if the future has been made ready. Use acquire MO
408 // to synchronize with the thread that made it ready.
409 if (_M_status._M_load(memory_order_acquire) == _Status::__ready)
410 return future_status::ready;
412 if (_M_is_deferred_future())
413 return future_status::deferred;
415 if (_M_status._M_load_when_equal_until(_Status::__ready,
416 memory_order_acquire,
419 // _GLIBCXX_RESOLVE_LIB_DEFECTS
420 // 2100. timed waiting functions must also join
421 // See wait_for(...) above.
424 return future_status::ready;
426 return future_status::timeout;
429 // Provide a result to the shared state and make it ready.
430 // Calls at most once: _M_result = __res();
432 _M_set_result(function<_Ptr_type()> __res, bool __ignore_failure = false)
434 bool __did_set = false;
435 // all calls to this function are serialized,
436 // side-effects of invoking __res only happen once
437 call_once(_M_once, &_State_baseV2::_M_do_set, this,
438 std::__addressof(__res), std::__addressof(__did_set));
440 // Use release MO to synchronize with observers of the ready state.
441 _M_status._M_store_notify_all(_Status::__ready,
442 memory_order_release);
443 else if (!__ignore_failure)
444 __throw_future_error(int(future_errc::promise_already_satisfied));
447 // Provide a result to the shared state but delay making it ready
448 // until the calling thread exits.
449 // Calls at most once: _M_result = __res();
451 _M_set_delayed_result(function<_Ptr_type()> __res,
452 weak_ptr<_State_baseV2> __self)
454 bool __did_set = false;
455 unique_ptr<_Make_ready> __mr{new _Make_ready};
456 // all calls to this function are serialized,
457 // side-effects of invoking __res only happen once
458 call_once(_M_once, &_State_baseV2::_M_do_set, this,
459 std::__addressof(__res), std::__addressof(__did_set));
461 __throw_future_error(int(future_errc::promise_already_satisfied));
462 __mr->_M_shared_state = std::move(__self);
467 // Abandon this shared state.
469 _M_break_promise(_Ptr_type __res)
471 if (static_cast<bool>(__res))
474 make_exception_ptr(future_error(future_errc::broken_promise));
475 // This function is only called when the last asynchronous result
476 // provider is abandoning this shared state, so noone can be
477 // trying to make the shared state ready at the same time, and
478 // we can access _M_result directly instead of through call_once.
479 _M_result.swap(__res);
480 // Use release MO to synchronize with observers of the ready state.
481 _M_status._M_store_notify_all(_Status::__ready,
482 memory_order_release);
486 // Called when this object is first passed to a future.
488 _M_set_retrieved_flag()
490 if (_M_retrieved.test_and_set())
491 __throw_future_error(int(future_errc::future_already_retrieved));
494 template<typename _Res, typename _Arg>
498 template<typename _Res, typename _Arg>
499 struct _Setter<_Res, _Arg&>
501 // check this is only used by promise<R>::set_value(const R&)
502 // or promise<R&>::set_value(R&)
503 static_assert(is_same<_Res, _Arg&>::value // promise<R&>
504 || is_same<const _Res, _Arg>::value, // promise<R>
505 "Invalid specialisation");
507 // Used by std::promise to copy construct the result.
508 typename promise<_Res>::_Ptr_type operator()() const
510 _M_promise->_M_storage->_M_set(*_M_arg);
511 return std::move(_M_promise->_M_storage);
513 promise<_Res>* _M_promise;
518 template<typename _Res>
519 struct _Setter<_Res, _Res&&>
521 // Used by std::promise to move construct the result.
522 typename promise<_Res>::_Ptr_type operator()() const
524 _M_promise->_M_storage->_M_set(std::move(*_M_arg));
525 return std::move(_M_promise->_M_storage);
527 promise<_Res>* _M_promise;
532 template<typename _Res>
533 struct _Setter<_Res, void>
535 static_assert(is_void<_Res>::value, "Only used for promise<void>");
537 typename promise<_Res>::_Ptr_type operator()() const noexcept
538 { return std::move(_M_promise->_M_storage); }
540 promise<_Res>* _M_promise;
543 struct __exception_ptr_tag { };
546 template<typename _Res>
547 struct _Setter<_Res, __exception_ptr_tag>
549 // Used by std::promise to store an exception as the result.
550 typename promise<_Res>::_Ptr_type operator()() const noexcept
552 _M_promise->_M_storage->_M_error = *_M_ex;
553 return std::move(_M_promise->_M_storage);
556 promise<_Res>* _M_promise;
557 exception_ptr* _M_ex;
560 template<typename _Res, typename _Arg>
561 __attribute__((__always_inline__))
562 static _Setter<_Res, _Arg&&>
563 __setter(promise<_Res>* __prom, _Arg&& __arg) noexcept
565 return _Setter<_Res, _Arg&&>{ __prom, std::__addressof(__arg) };
568 template<typename _Res>
569 __attribute__((__always_inline__))
570 static _Setter<_Res, __exception_ptr_tag>
571 __setter(exception_ptr& __ex, promise<_Res>* __prom) noexcept
573 __glibcxx_assert(__ex != nullptr); // LWG 2276
574 return _Setter<_Res, __exception_ptr_tag>{ __prom, &__ex };
577 template<typename _Res>
578 __attribute__((__always_inline__))
579 static _Setter<_Res, void>
580 __setter(promise<_Res>* __prom) noexcept
582 return _Setter<_Res, void>{ __prom };
585 template<typename _Tp>
587 _S_check(const shared_ptr<_Tp>& __p)
589 if (!static_cast<bool>(__p))
590 __throw_future_error((int)future_errc::no_state);
594 // The function invoked with std::call_once(_M_once, ...).
596 _M_do_set(function<_Ptr_type()>* __f, bool* __did_set)
598 _Ptr_type __res = (*__f)();
599 // Notify the caller that we did try to set; if we do not throw an
600 // exception, the caller will be aware that it did set (e.g., see
603 _M_result.swap(__res); // nothrow
606 // Wait for completion of async function.
607 virtual void _M_complete_async() { }
609 // Return true if state corresponds to a deferred function.
610 virtual bool _M_is_deferred_future() const { return false; }
612 struct _Make_ready final : __at_thread_exit_elt
614 weak_ptr<_State_baseV2> _M_shared_state;
615 static void _S_run(void*);
620 #ifdef _GLIBCXX_ASYNC_ABI_COMPAT
622 class _Async_state_common;
624 using _State_base = _State_baseV2;
625 class _Async_state_commonV2;
628 template<typename _BoundFn,
629 typename _Res = decltype(std::declval<_BoundFn&>()())>
630 class _Deferred_state;
632 template<typename _BoundFn,
633 typename _Res = decltype(std::declval<_BoundFn&>()())>
634 class _Async_state_impl;
636 template<typename _Signature>
637 struct _Task_state_base;
639 template<typename _Fn, typename _Alloc, typename _Signature>
642 template<typename _Res_ptr, typename _Fn,
643 typename _Res = typename _Res_ptr::element_type::result_type>
646 template<typename _Res_ptr, typename _BoundFn>
647 static _Task_setter<_Res_ptr, _BoundFn>
648 _S_task_setter(_Res_ptr& __ptr, _BoundFn& __call)
650 return { std::__addressof(__ptr), std::__addressof(__call) };
654 /// Partial specialization for reference types.
655 template<typename _Res>
656 struct __future_base::_Result<_Res&> : __future_base::_Result_base
658 typedef _Res& result_type;
660 _Result() noexcept : _M_value_ptr() { }
663 _M_set(_Res& __res) noexcept
664 { _M_value_ptr = std::addressof(__res); }
666 _Res& _M_get() noexcept { return *_M_value_ptr; }
671 void _M_destroy() { delete this; }
674 /// Explicit specialization for void.
676 struct __future_base::_Result<void> : __future_base::_Result_base
678 typedef void result_type;
681 void _M_destroy() { delete this; }
686 #ifndef _GLIBCXX_ASYNC_ABI_COMPAT
688 /// @cond undocumented
689 // Allow _Setter objects to be stored locally in std::function
690 template<typename _Res, typename _Arg>
691 struct __is_location_invariant
692 <__future_base::_State_base::_Setter<_Res, _Arg>>
695 // Allow _Task_setter objects to be stored locally in std::function
696 template<typename _Res_ptr, typename _Fn, typename _Res>
697 struct __is_location_invariant
698 <__future_base::_Task_setter<_Res_ptr, _Fn, _Res>>
702 /// Common implementation for future and shared_future.
703 template<typename _Res>
704 class __basic_future : public __future_base
707 typedef shared_ptr<_State_base> __state_type;
708 typedef __future_base::_Result<_Res>& __result_type;
711 __state_type _M_state;
715 __basic_future(const __basic_future&) = delete;
716 __basic_future& operator=(const __basic_future&) = delete;
719 valid() const noexcept { return static_cast<bool>(_M_state); }
724 _State_base::_S_check(_M_state);
728 template<typename _Rep, typename _Period>
730 wait_for(const chrono::duration<_Rep, _Period>& __rel) const
732 _State_base::_S_check(_M_state);
733 return _M_state->wait_for(__rel);
736 template<typename _Clock, typename _Duration>
738 wait_until(const chrono::time_point<_Clock, _Duration>& __abs) const
740 _State_base::_S_check(_M_state);
741 return _M_state->wait_until(__abs);
745 /// Wait for the state to be ready and rethrow any stored exception
747 _M_get_result() const
749 _State_base::_S_check(_M_state);
750 _Result_base& __res = _M_state->wait();
751 if (!(__res._M_error == nullptr))
752 rethrow_exception(__res._M_error);
753 return static_cast<__result_type>(__res);
756 void _M_swap(__basic_future& __that) noexcept
758 _M_state.swap(__that._M_state);
761 // Construction of a future by promise::get_future()
763 __basic_future(const __state_type& __state) : _M_state(__state)
765 _State_base::_S_check(_M_state);
766 _M_state->_M_set_retrieved_flag();
769 // Copy construction from a shared_future
771 __basic_future(const shared_future<_Res>&) noexcept;
773 // Move construction from a shared_future
775 __basic_future(shared_future<_Res>&&) noexcept;
777 // Move construction from a future
779 __basic_future(future<_Res>&&) noexcept;
781 constexpr __basic_future() noexcept : _M_state() { }
785 explicit _Reset(__basic_future& __fut) noexcept : _M_fut(__fut) { }
786 ~_Reset() { _M_fut._M_state.reset(); }
787 __basic_future& _M_fut;
792 /// Primary template for future.
793 template<typename _Res>
794 class future : public __basic_future<_Res>
796 // _GLIBCXX_RESOLVE_LIB_DEFECTS
797 // 3458. Is shared_future intended to work with arrays or function types?
798 static_assert(!is_array<_Res>{}, "result type must not be an array");
799 static_assert(!is_function<_Res>{}, "result type must not be a function");
800 static_assert(is_destructible<_Res>{},
801 "result type must be destructible");
803 friend class promise<_Res>;
804 template<typename> friend class packaged_task;
805 template<typename _Fn, typename... _Args>
806 friend future<__async_result_of<_Fn, _Args...>>
807 async(launch, _Fn&&, _Args&&...);
809 typedef __basic_future<_Res> _Base_type;
810 typedef typename _Base_type::__state_type __state_type;
813 future(const __state_type& __state) : _Base_type(__state) { }
816 constexpr future() noexcept : _Base_type() { }
819 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { }
822 future(const future&) = delete;
823 future& operator=(const future&) = delete;
825 future& operator=(future&& __fut) noexcept
827 future(std::move(__fut))._M_swap(*this);
831 /// Retrieving the value
835 typename _Base_type::_Reset __reset(*this);
836 return std::move(this->_M_get_result()._M_value());
839 shared_future<_Res> share() noexcept;
842 /// Partial specialization for future<R&>
843 template<typename _Res>
844 class future<_Res&> : public __basic_future<_Res&>
846 friend class promise<_Res&>;
847 template<typename> friend class packaged_task;
848 template<typename _Fn, typename... _Args>
849 friend future<__async_result_of<_Fn, _Args...>>
850 async(launch, _Fn&&, _Args&&...);
852 typedef __basic_future<_Res&> _Base_type;
853 typedef typename _Base_type::__state_type __state_type;
856 future(const __state_type& __state) : _Base_type(__state) { }
859 constexpr future() noexcept : _Base_type() { }
862 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { }
865 future(const future&) = delete;
866 future& operator=(const future&) = delete;
868 future& operator=(future&& __fut) noexcept
870 future(std::move(__fut))._M_swap(*this);
874 /// Retrieving the value
878 typename _Base_type::_Reset __reset(*this);
879 return this->_M_get_result()._M_get();
882 shared_future<_Res&> share() noexcept;
885 /// Explicit specialization for future<void>
887 class future<void> : public __basic_future<void>
889 friend class promise<void>;
890 template<typename> friend class packaged_task;
891 template<typename _Fn, typename... _Args>
892 friend future<__async_result_of<_Fn, _Args...>>
893 async(launch, _Fn&&, _Args&&...);
895 typedef __basic_future<void> _Base_type;
896 typedef typename _Base_type::__state_type __state_type;
899 future(const __state_type& __state) : _Base_type(__state) { }
902 constexpr future() noexcept : _Base_type() { }
905 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { }
908 future(const future&) = delete;
909 future& operator=(const future&) = delete;
911 future& operator=(future&& __fut) noexcept
913 future(std::move(__fut))._M_swap(*this);
917 /// Retrieving the value
921 typename _Base_type::_Reset __reset(*this);
922 this->_M_get_result();
925 shared_future<void> share() noexcept;
929 /// Primary template for shared_future.
930 template<typename _Res>
931 class shared_future : public __basic_future<_Res>
933 // _GLIBCXX_RESOLVE_LIB_DEFECTS
934 // 3458. Is shared_future intended to work with arrays or function types?
935 static_assert(!is_array<_Res>{}, "result type must not be an array");
936 static_assert(!is_function<_Res>{}, "result type must not be a function");
937 static_assert(is_destructible<_Res>{},
938 "result type must be destructible");
940 typedef __basic_future<_Res> _Base_type;
943 constexpr shared_future() noexcept : _Base_type() { }
946 shared_future(const shared_future& __sf) noexcept : _Base_type(__sf) { }
948 /// Construct from a future rvalue
949 shared_future(future<_Res>&& __uf) noexcept
950 : _Base_type(std::move(__uf))
953 /// Construct from a shared_future rvalue
954 shared_future(shared_future&& __sf) noexcept
955 : _Base_type(std::move(__sf))
958 shared_future& operator=(const shared_future& __sf) noexcept
960 shared_future(__sf)._M_swap(*this);
964 shared_future& operator=(shared_future&& __sf) noexcept
966 shared_future(std::move(__sf))._M_swap(*this);
970 /// Retrieving the value
972 get() const { return this->_M_get_result()._M_value(); }
975 /// Partial specialization for shared_future<R&>
976 template<typename _Res>
977 class shared_future<_Res&> : public __basic_future<_Res&>
979 typedef __basic_future<_Res&> _Base_type;
982 constexpr shared_future() noexcept : _Base_type() { }
985 shared_future(const shared_future& __sf) : _Base_type(__sf) { }
987 /// Construct from a future rvalue
988 shared_future(future<_Res&>&& __uf) noexcept
989 : _Base_type(std::move(__uf))
992 /// Construct from a shared_future rvalue
993 shared_future(shared_future&& __sf) noexcept
994 : _Base_type(std::move(__sf))
997 shared_future& operator=(const shared_future& __sf)
999 shared_future(__sf)._M_swap(*this);
1003 shared_future& operator=(shared_future&& __sf) noexcept
1005 shared_future(std::move(__sf))._M_swap(*this);
1009 /// Retrieving the value
1011 get() const { return this->_M_get_result()._M_get(); }
1014 /// Explicit specialization for shared_future<void>
1016 class shared_future<void> : public __basic_future<void>
1018 typedef __basic_future<void> _Base_type;
1021 constexpr shared_future() noexcept : _Base_type() { }
1023 /// Copy constructor
1024 shared_future(const shared_future& __sf) : _Base_type(__sf) { }
1026 /// Construct from a future rvalue
1027 shared_future(future<void>&& __uf) noexcept
1028 : _Base_type(std::move(__uf))
1031 /// Construct from a shared_future rvalue
1032 shared_future(shared_future&& __sf) noexcept
1033 : _Base_type(std::move(__sf))
1036 shared_future& operator=(const shared_future& __sf)
1038 shared_future(__sf)._M_swap(*this);
1042 shared_future& operator=(shared_future&& __sf) noexcept
1044 shared_future(std::move(__sf))._M_swap(*this);
1048 // Retrieving the value
1050 get() const { this->_M_get_result(); }
1053 // Now we can define the protected __basic_future constructors.
1054 template<typename _Res>
1055 inline __basic_future<_Res>::
1056 __basic_future(const shared_future<_Res>& __sf) noexcept
1057 : _M_state(__sf._M_state)
1060 template<typename _Res>
1061 inline __basic_future<_Res>::
1062 __basic_future(shared_future<_Res>&& __sf) noexcept
1063 : _M_state(std::move(__sf._M_state))
1066 template<typename _Res>
1067 inline __basic_future<_Res>::
1068 __basic_future(future<_Res>&& __uf) noexcept
1069 : _M_state(std::move(__uf._M_state))
1072 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1073 // 2556. Wide contract for future::share()
1074 template<typename _Res>
1075 inline shared_future<_Res>
1076 future<_Res>::share() noexcept
1077 { return shared_future<_Res>(std::move(*this)); }
1079 template<typename _Res>
1080 inline shared_future<_Res&>
1081 future<_Res&>::share() noexcept
1082 { return shared_future<_Res&>(std::move(*this)); }
1084 inline shared_future<void>
1085 future<void>::share() noexcept
1086 { return shared_future<void>(std::move(*this)); }
1088 /// Primary template for promise
1089 template<typename _Res>
1092 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1093 // 3466: Specify the requirements for promise/future/[...] consistently
1094 static_assert(!is_array<_Res>{}, "result type must not be an array");
1095 static_assert(!is_function<_Res>{}, "result type must not be a function");
1096 static_assert(is_destructible<_Res>{},
1097 "result type must be destructible");
1099 typedef __future_base::_State_base _State;
1100 typedef __future_base::_Result<_Res> _Res_type;
1101 typedef __future_base::_Ptr<_Res_type> _Ptr_type;
1102 template<typename, typename> friend struct _State::_Setter;
1105 shared_ptr<_State> _M_future;
1106 _Ptr_type _M_storage;
1110 : _M_future(std::make_shared<_State>()),
1111 _M_storage(new _Res_type())
1114 promise(promise&& __rhs) noexcept
1115 : _M_future(std::move(__rhs._M_future)),
1116 _M_storage(std::move(__rhs._M_storage))
1119 template<typename _Allocator>
1120 promise(allocator_arg_t, const _Allocator& __a)
1121 : _M_future(std::allocate_shared<_State>(__a)),
1122 _M_storage(__future_base::_S_allocate_result<_Res>(__a))
1125 template<typename _Allocator>
1126 promise(allocator_arg_t, const _Allocator&, promise&& __rhs)
1127 : _M_future(std::move(__rhs._M_future)),
1128 _M_storage(std::move(__rhs._M_storage))
1131 promise(const promise&) = delete;
1135 if (static_cast<bool>(_M_future) && !_M_future.unique())
1136 _M_future->_M_break_promise(std::move(_M_storage));
1141 operator=(promise&& __rhs) noexcept
1143 promise(std::move(__rhs)).swap(*this);
1147 promise& operator=(const promise&) = delete;
1150 swap(promise& __rhs) noexcept
1152 _M_future.swap(__rhs._M_future);
1153 _M_storage.swap(__rhs._M_storage);
1156 // Retrieving the result
1159 { return future<_Res>(_M_future); }
1161 // Setting the result
1163 set_value(const _Res& __r)
1164 { _M_state()._M_set_result(_State::__setter(this, __r)); }
1167 set_value(_Res&& __r)
1168 { _M_state()._M_set_result(_State::__setter(this, std::move(__r))); }
1171 set_exception(exception_ptr __p)
1172 { _M_state()._M_set_result(_State::__setter(__p, this)); }
1175 set_value_at_thread_exit(const _Res& __r)
1177 _M_state()._M_set_delayed_result(_State::__setter(this, __r),
1182 set_value_at_thread_exit(_Res&& __r)
1184 _M_state()._M_set_delayed_result(
1185 _State::__setter(this, std::move(__r)), _M_future);
1189 set_exception_at_thread_exit(exception_ptr __p)
1191 _M_state()._M_set_delayed_result(_State::__setter(__p, this),
1199 __future_base::_State_base::_S_check(_M_future);
1204 template<typename _Res>
1206 swap(promise<_Res>& __x, promise<_Res>& __y) noexcept
1209 template<typename _Res, typename _Alloc>
1210 struct uses_allocator<promise<_Res>, _Alloc>
1211 : public true_type { };
1214 /// Partial specialization for promise<R&>
1215 template<typename _Res>
1216 class promise<_Res&>
1218 typedef __future_base::_State_base _State;
1219 typedef __future_base::_Result<_Res&> _Res_type;
1220 typedef __future_base::_Ptr<_Res_type> _Ptr_type;
1221 template<typename, typename> friend struct _State::_Setter;
1224 shared_ptr<_State> _M_future;
1225 _Ptr_type _M_storage;
1229 : _M_future(std::make_shared<_State>()),
1230 _M_storage(new _Res_type())
1233 promise(promise&& __rhs) noexcept
1234 : _M_future(std::move(__rhs._M_future)),
1235 _M_storage(std::move(__rhs._M_storage))
1238 template<typename _Allocator>
1239 promise(allocator_arg_t, const _Allocator& __a)
1240 : _M_future(std::allocate_shared<_State>(__a)),
1241 _M_storage(__future_base::_S_allocate_result<_Res&>(__a))
1244 template<typename _Allocator>
1245 promise(allocator_arg_t, const _Allocator&, promise&& __rhs)
1246 : _M_future(std::move(__rhs._M_future)),
1247 _M_storage(std::move(__rhs._M_storage))
1250 promise(const promise&) = delete;
1254 if (static_cast<bool>(_M_future) && !_M_future.unique())
1255 _M_future->_M_break_promise(std::move(_M_storage));
1260 operator=(promise&& __rhs) noexcept
1262 promise(std::move(__rhs)).swap(*this);
1266 promise& operator=(const promise&) = delete;
1269 swap(promise& __rhs) noexcept
1271 _M_future.swap(__rhs._M_future);
1272 _M_storage.swap(__rhs._M_storage);
1275 // Retrieving the result
1278 { return future<_Res&>(_M_future); }
1280 // Setting the result
1282 set_value(_Res& __r)
1283 { _M_state()._M_set_result(_State::__setter(this, __r)); }
1286 set_exception(exception_ptr __p)
1287 { _M_state()._M_set_result(_State::__setter(__p, this)); }
1290 set_value_at_thread_exit(_Res& __r)
1292 _M_state()._M_set_delayed_result(_State::__setter(this, __r),
1297 set_exception_at_thread_exit(exception_ptr __p)
1299 _M_state()._M_set_delayed_result(_State::__setter(__p, this),
1307 __future_base::_State_base::_S_check(_M_future);
1312 /// Explicit specialization for promise<void>
1316 typedef __future_base::_State_base _State;
1317 typedef __future_base::_Result<void> _Res_type;
1318 typedef __future_base::_Ptr<_Res_type> _Ptr_type;
1319 template<typename, typename> friend struct _State::_Setter;
1322 shared_ptr<_State> _M_future;
1323 _Ptr_type _M_storage;
1327 : _M_future(std::make_shared<_State>()),
1328 _M_storage(new _Res_type())
1331 promise(promise&& __rhs) noexcept
1332 : _M_future(std::move(__rhs._M_future)),
1333 _M_storage(std::move(__rhs._M_storage))
1336 template<typename _Allocator>
1337 promise(allocator_arg_t, const _Allocator& __a)
1338 : _M_future(std::allocate_shared<_State>(__a)),
1339 _M_storage(__future_base::_S_allocate_result<void>(__a))
1342 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1343 // 2095. missing constructors needed for uses-allocator construction
1344 template<typename _Allocator>
1345 promise(allocator_arg_t, const _Allocator&, promise&& __rhs)
1346 : _M_future(std::move(__rhs._M_future)),
1347 _M_storage(std::move(__rhs._M_storage))
1350 promise(const promise&) = delete;
1354 if (static_cast<bool>(_M_future) && !_M_future.unique())
1355 _M_future->_M_break_promise(std::move(_M_storage));
1360 operator=(promise&& __rhs) noexcept
1362 promise(std::move(__rhs)).swap(*this);
1366 promise& operator=(const promise&) = delete;
1369 swap(promise& __rhs) noexcept
1371 _M_future.swap(__rhs._M_future);
1372 _M_storage.swap(__rhs._M_storage);
1375 // Retrieving the result
1378 { return future<void>(_M_future); }
1380 // Setting the result
1383 { _M_state()._M_set_result(_State::__setter(this)); }
1386 set_exception(exception_ptr __p)
1387 { _M_state()._M_set_result(_State::__setter(__p, this)); }
1390 set_value_at_thread_exit()
1391 { _M_state()._M_set_delayed_result(_State::__setter(this), _M_future); }
1394 set_exception_at_thread_exit(exception_ptr __p)
1396 _M_state()._M_set_delayed_result(_State::__setter(__p, this),
1404 __future_base::_State_base::_S_check(_M_future);
1409 /// @cond undocumented
1410 template<typename _Ptr_type, typename _Fn, typename _Res>
1411 struct __future_base::_Task_setter
1413 // Invoke the function and provide the result to the caller.
1414 _Ptr_type operator()() const
1418 (*_M_result)->_M_set((*_M_fn)());
1420 __catch(const __cxxabiv1::__forced_unwind&)
1422 __throw_exception_again; // will cause broken_promise
1426 (*_M_result)->_M_error = current_exception();
1428 return std::move(*_M_result);
1430 _Ptr_type* _M_result;
1434 template<typename _Ptr_type, typename _Fn>
1435 struct __future_base::_Task_setter<_Ptr_type, _Fn, void>
1437 _Ptr_type operator()() const
1443 __catch(const __cxxabiv1::__forced_unwind&)
1445 __throw_exception_again; // will cause broken_promise
1449 (*_M_result)->_M_error = current_exception();
1451 return std::move(*_M_result);
1453 _Ptr_type* _M_result;
1457 // Holds storage for a packaged_task's result.
1458 template<typename _Res, typename... _Args>
1459 struct __future_base::_Task_state_base<_Res(_Args...)>
1460 : __future_base::_State_base
1462 typedef _Res _Res_type;
1464 template<typename _Alloc>
1465 _Task_state_base(const _Alloc& __a)
1466 : _M_result(_S_allocate_result<_Res>(__a))
1469 // Invoke the stored task and make the state ready.
1471 _M_run(_Args&&... __args) = 0;
1473 // Invoke the stored task and make the state ready at thread exit.
1475 _M_run_delayed(_Args&&... __args, weak_ptr<_State_base>) = 0;
1477 virtual shared_ptr<_Task_state_base>
1480 typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type;
1481 _Ptr_type _M_result;
1484 // Holds a packaged_task's stored task.
1485 template<typename _Fn, typename _Alloc, typename _Res, typename... _Args>
1486 struct __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)> final
1487 : __future_base::_Task_state_base<_Res(_Args...)>
1489 #ifdef __cpp_lib_is_invocable // C++ >= 17
1490 static_assert(is_invocable_r_v<_Res, _Fn&, _Args...>);
1492 static_assert(__is_invocable<_Fn&, _Args...>::value,
1493 "_Fn& is invocable with _Args...");
1496 template<typename _Fn2>
1497 _Task_state(_Fn2&& __fn, const _Alloc& __a)
1498 : _Task_state_base<_Res(_Args...)>(__a),
1499 _M_impl(std::forward<_Fn2>(__fn), __a)
1502 template<typename _Fn2>
1503 static shared_ptr<_Task_state_base<_Res(_Args...)>>
1504 _S_create(_Fn2&& __fn, const _Alloc& __a)
1506 return std::allocate_shared<_Task_state>(__a,
1507 std::forward<_Fn2>(__fn),
1513 _M_run(_Args&&... __args)
1515 auto __boundfn = [&] () -> _Res {
1516 return std::__invoke_r<_Res>(_M_impl._M_fn,
1517 std::forward<_Args>(__args)...);
1519 this->_M_set_result(_S_task_setter(this->_M_result, __boundfn));
1523 _M_run_delayed(_Args&&... __args, weak_ptr<_State_base> __self)
1525 auto __boundfn = [&] () -> _Res {
1526 return std::__invoke_r<_Res>(_M_impl._M_fn,
1527 std::forward<_Args>(__args)...);
1529 this->_M_set_delayed_result(_S_task_setter(this->_M_result, __boundfn),
1533 virtual shared_ptr<_Task_state_base<_Res(_Args...)>>
1535 { return _S_create(std::move(_M_impl._M_fn), _M_impl); }
1537 struct _Impl : _Alloc
1539 template<typename _Fn2>
1540 _Impl(_Fn2&& __fn, const _Alloc& __a)
1541 : _Alloc(__a), _M_fn(std::forward<_Fn2>(__fn)) { }
1548 template<typename _Res, typename... _ArgTypes>
1549 class packaged_task<_Res(_ArgTypes...)>
1551 using _State_type = __future_base::_Task_state_base<_Res(_ArgTypes...)>;
1552 shared_ptr<_State_type> _M_state;
1554 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1555 // 3039. Unnecessary decay in thread and packaged_task
1556 template<typename _Fn, typename _Fn2 = __remove_cvref_t<_Fn>>
1557 using __not_same = __enable_if_t<!is_same<packaged_task, _Fn2>::value>;
1559 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1560 // 4154. The Mandates for std::packaged_task's constructor
1561 // from a callable entity should consider decaying.
1562 template<typename _Fn, typename _Alloc = std::allocator<int>>
1564 = __future_base::_Task_state<__decay_t<_Fn>, _Alloc,
1565 _Res(_ArgTypes...)>;
1568 // Construction and destruction
1569 packaged_task() noexcept { }
1571 template<typename _Fn, typename = __not_same<_Fn>>
1573 packaged_task(_Fn&& __fn)
1574 : _M_state(_Task_state<_Fn>::_S_create(std::forward<_Fn>(__fn), {}))
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(_Task_state<_Fn, _Alloc>::_S_create(std::forward<_Fn>(__fn),
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)...);
1822 #if __cpp_exceptions
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