2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_FUTURE
11 #define _LIBCPP_FUTURE
19 enum class future_errc
21 future_already_retrieved = 1,
22 promise_already_satisfied,
31 any = async | deferred
34 enum class future_status
41 template <> struct is_error_code_enum<future_errc> : public true_type { };
42 error_code make_error_code(future_errc e) noexcept;
43 error_condition make_error_condition(future_errc e) noexcept;
45 const error_category& future_category() noexcept;
51 future_error(error_code ec); // exposition only
52 explicit future_error(future_errc); // C++17
53 const error_code& code() const noexcept;
54 const char* what() const noexcept;
62 template <class Allocator>
63 promise(allocator_arg_t, const Allocator& a);
64 promise(promise&& rhs) noexcept;
65 promise(const promise& rhs) = delete;
69 promise& operator=(promise&& rhs) noexcept;
70 promise& operator=(const promise& rhs) = delete;
71 void swap(promise& other) noexcept;
73 // retrieving the result
74 future<R> get_future();
77 void set_value(const R& r);
78 void set_value(R&& r);
79 void set_exception(exception_ptr p);
81 // setting the result with deferred notification
82 void set_value_at_thread_exit(const R& r);
83 void set_value_at_thread_exit(R&& r);
84 void set_exception_at_thread_exit(exception_ptr p);
92 template <class Allocator>
93 promise(allocator_arg_t, const Allocator& a);
94 promise(promise&& rhs) noexcept;
95 promise(const promise& rhs) = delete;
99 promise& operator=(promise&& rhs) noexcept;
100 promise& operator=(const promise& rhs) = delete;
101 void swap(promise& other) noexcept;
103 // retrieving the result
104 future<R&> get_future();
106 // setting the result
107 void set_value(R& r);
108 void set_exception(exception_ptr p);
110 // setting the result with deferred notification
111 void set_value_at_thread_exit(R&);
112 void set_exception_at_thread_exit(exception_ptr p);
120 template <class Allocator>
121 promise(allocator_arg_t, const Allocator& a);
122 promise(promise&& rhs) noexcept;
123 promise(const promise& rhs) = delete;
127 promise& operator=(promise&& rhs) noexcept;
128 promise& operator=(const promise& rhs) = delete;
129 void swap(promise& other) noexcept;
131 // retrieving the result
132 future<void> get_future();
134 // setting the result
136 void set_exception(exception_ptr p);
138 // setting the result with deferred notification
139 void set_value_at_thread_exit();
140 void set_exception_at_thread_exit(exception_ptr p);
143 template <class R> void swap(promise<R>& x, promise<R>& y) noexcept;
145 template <class R, class Alloc>
146 struct uses_allocator<promise<R>, Alloc> : public true_type {};
153 future(future&&) noexcept;
154 future(const future& rhs) = delete;
156 future& operator=(const future& rhs) = delete;
157 future& operator=(future&&) noexcept;
158 shared_future<R> share() noexcept;
160 // retrieving the value
163 // functions to check state
164 bool valid() const noexcept;
167 template <class Rep, class Period>
169 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
170 template <class Clock, class Duration>
172 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
180 future(future&&) noexcept;
181 future(const future& rhs) = delete;
183 future& operator=(const future& rhs) = delete;
184 future& operator=(future&&) noexcept;
185 shared_future<R&> share() noexcept;
187 // retrieving the value
190 // functions to check state
191 bool valid() const noexcept;
194 template <class Rep, class Period>
196 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
197 template <class Clock, class Duration>
199 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
207 future(future&&) noexcept;
208 future(const future& rhs) = delete;
210 future& operator=(const future& rhs) = delete;
211 future& operator=(future&&) noexcept;
212 shared_future<void> share() noexcept;
214 // retrieving the value
217 // functions to check state
218 bool valid() const noexcept;
221 template <class Rep, class Period>
223 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
224 template <class Clock, class Duration>
226 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
233 shared_future() noexcept;
234 shared_future(const shared_future& rhs);
235 shared_future(future<R>&&) noexcept;
236 shared_future(shared_future&& rhs) noexcept;
238 shared_future& operator=(const shared_future& rhs);
239 shared_future& operator=(shared_future&& rhs) noexcept;
241 // retrieving the value
242 const R& get() const;
244 // functions to check state
245 bool valid() const noexcept;
248 template <class Rep, class Period>
250 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
251 template <class Clock, class Duration>
253 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
257 class shared_future<R&>
260 shared_future() noexcept;
261 shared_future(const shared_future& rhs);
262 shared_future(future<R&>&&) noexcept;
263 shared_future(shared_future&& rhs) noexcept;
265 shared_future& operator=(const shared_future& rhs);
266 shared_future& operator=(shared_future&& rhs) noexcept;
268 // retrieving the value
271 // functions to check state
272 bool valid() const noexcept;
275 template <class Rep, class Period>
277 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
278 template <class Clock, class Duration>
280 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
284 class shared_future<void>
287 shared_future() noexcept;
288 shared_future(const shared_future& rhs);
289 shared_future(future<void>&&) noexcept;
290 shared_future(shared_future&& rhs) noexcept;
292 shared_future& operator=(const shared_future& rhs);
293 shared_future& operator=(shared_future&& rhs) noexcept;
295 // retrieving the value
298 // functions to check state
299 bool valid() const noexcept;
302 template <class Rep, class Period>
304 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
305 template <class Clock, class Duration>
307 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
310 template <class F, class... Args>
311 future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
312 async(F&& f, Args&&... args);
314 template <class F, class... Args>
315 future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
316 async(launch policy, F&& f, Args&&... args);
318 template <class> class packaged_task; // undefined
320 template <class R, class... ArgTypes>
321 class packaged_task<R(ArgTypes...)>
324 typedef R result_type; // extension
326 // construction and destruction
327 packaged_task() noexcept;
329 explicit packaged_task(F&& f);
330 template <class F, class Allocator>
331 packaged_task(allocator_arg_t, const Allocator& a, F&& f);
335 packaged_task(const packaged_task&) = delete;
336 packaged_task& operator=(const packaged_task&) = delete;
339 packaged_task(packaged_task&& other) noexcept;
340 packaged_task& operator=(packaged_task&& other) noexcept;
341 void swap(packaged_task& other) noexcept;
343 bool valid() const noexcept;
346 future<R> get_future();
349 void operator()(ArgTypes... );
350 void make_ready_at_thread_exit(ArgTypes...);
356 void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&) noexcept;
358 template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
364 #include <__availability>
367 #include <__memory/allocator_arg_t.h>
368 #include <__memory/uses_allocator.h>
369 #include <__utility/auto_cast.h>
370 #include <__utility/forward.h>
375 #include <system_error>
379 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
380 #pragma GCC system_header
383 #ifdef _LIBCPP_HAS_NO_THREADS
384 #error <future> is not supported on this single threaded system
385 #else // !_LIBCPP_HAS_NO_THREADS
387 _LIBCPP_BEGIN_NAMESPACE_STD
389 //enum class future_errc
390 _LIBCPP_DECLARE_STRONG_ENUM(future_errc)
392 future_already_retrieved = 1,
393 promise_already_satisfied,
397 _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc)
400 struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc> : public true_type {};
402 #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
404 struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc::__lx> : public true_type { };
408 _LIBCPP_DECLARE_STRONG_ENUM(launch)
412 any = async | deferred
414 _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch)
416 #ifndef _LIBCPP_HAS_NO_STRONG_ENUMS
418 typedef underlying_type<launch>::type __launch_underlying_type;
420 inline _LIBCPP_INLINE_VISIBILITY
423 operator&(launch __x, launch __y)
425 return static_cast<launch>(static_cast<__launch_underlying_type>(__x) &
426 static_cast<__launch_underlying_type>(__y));
429 inline _LIBCPP_INLINE_VISIBILITY
432 operator|(launch __x, launch __y)
434 return static_cast<launch>(static_cast<__launch_underlying_type>(__x) |
435 static_cast<__launch_underlying_type>(__y));
438 inline _LIBCPP_INLINE_VISIBILITY
441 operator^(launch __x, launch __y)
443 return static_cast<launch>(static_cast<__launch_underlying_type>(__x) ^
444 static_cast<__launch_underlying_type>(__y));
447 inline _LIBCPP_INLINE_VISIBILITY
450 operator~(launch __x)
452 return static_cast<launch>(~static_cast<__launch_underlying_type>(__x) & 3);
455 inline _LIBCPP_INLINE_VISIBILITY
457 operator&=(launch& __x, launch __y)
459 __x = __x & __y; return __x;
462 inline _LIBCPP_INLINE_VISIBILITY
464 operator|=(launch& __x, launch __y)
466 __x = __x | __y; return __x;
469 inline _LIBCPP_INLINE_VISIBILITY
471 operator^=(launch& __x, launch __y)
473 __x = __x ^ __y; return __x;
476 #endif // !_LIBCPP_HAS_NO_STRONG_ENUMS
478 //enum class future_status
479 _LIBCPP_DECLARE_STRONG_ENUM(future_status)
485 _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_status)
488 const error_category& future_category() _NOEXCEPT;
490 inline _LIBCPP_INLINE_VISIBILITY
492 make_error_code(future_errc __e) _NOEXCEPT
494 return error_code(static_cast<int>(__e), future_category());
497 inline _LIBCPP_INLINE_VISIBILITY
499 make_error_condition(future_errc __e) _NOEXCEPT
501 return error_condition(static_cast<int>(__e), future_category());
504 class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_FUTURE_ERROR future_error
509 future_error(error_code __ec);
511 _LIBCPP_INLINE_VISIBILITY
512 const error_code& code() const _NOEXCEPT {return __ec_;}
514 future_error(const future_error&) _NOEXCEPT = default;
515 virtual ~future_error() _NOEXCEPT;
518 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
519 #ifndef _LIBCPP_NO_EXCEPTIONS
520 _LIBCPP_AVAILABILITY_FUTURE_ERROR
522 void __throw_future_error(future_errc _Ev)
524 #ifndef _LIBCPP_NO_EXCEPTIONS
525 throw future_error(make_error_code(_Ev));
532 class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE __assoc_sub_state
533 : public __shared_count
536 exception_ptr __exception_;
537 mutable mutex __mut_;
538 mutable condition_variable __cv_;
541 virtual void __on_zero_shared() _NOEXCEPT;
542 void __sub_wait(unique_lock<mutex>& __lk);
547 __future_attached = 2,
552 _LIBCPP_INLINE_VISIBILITY
553 __assoc_sub_state() : __state_(0) {}
555 _LIBCPP_INLINE_VISIBILITY
556 bool __has_value() const
557 {return (__state_ & __constructed) || (__exception_ != nullptr);}
559 _LIBCPP_INLINE_VISIBILITY
560 void __attach_future() {
561 lock_guard<mutex> __lk(__mut_);
562 bool __has_future_attached = (__state_ & __future_attached) != 0;
563 if (__has_future_attached)
564 __throw_future_error(future_errc::future_already_retrieved);
565 this->__add_shared();
566 __state_ |= __future_attached;
569 _LIBCPP_INLINE_VISIBILITY
570 void __set_deferred() {__state_ |= deferred;}
573 _LIBCPP_INLINE_VISIBILITY
574 bool __is_ready() const {return (__state_ & ready) != 0;}
577 void set_value_at_thread_exit();
579 void set_exception(exception_ptr __p);
580 void set_exception_at_thread_exit(exception_ptr __p);
585 template <class _Rep, class _Period>
587 _LIBCPP_INLINE_VISIBILITY
588 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const;
589 template <class _Clock, class _Duration>
590 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
592 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const;
594 virtual void __execute();
597 template <class _Clock, class _Duration>
599 __assoc_sub_state::wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
601 unique_lock<mutex> __lk(__mut_);
602 if (__state_ & deferred)
603 return future_status::deferred;
604 while (!(__state_ & ready) && _Clock::now() < __abs_time)
605 __cv_.wait_until(__lk, __abs_time);
606 if (__state_ & ready)
607 return future_status::ready;
608 return future_status::timeout;
611 template <class _Rep, class _Period>
614 __assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
616 return wait_until(chrono::steady_clock::now() + __rel_time);
620 class _LIBCPP_AVAILABILITY_FUTURE _LIBCPP_HIDDEN __assoc_state
621 : public __assoc_sub_state
623 typedef __assoc_sub_state base;
624 typedef typename aligned_storage<sizeof(_Rp), alignment_of<_Rp>::value>::type _Up;
628 virtual void __on_zero_shared() _NOEXCEPT;
631 template <class _Arg>
632 void set_value(_Arg&& __arg);
634 template <class _Arg>
635 void set_value_at_thread_exit(_Arg&& __arg);
638 typename add_lvalue_reference<_Rp>::type copy();
643 __assoc_state<_Rp>::__on_zero_shared() _NOEXCEPT
645 if (this->__state_ & base::__constructed)
646 reinterpret_cast<_Rp*>(&__value_)->~_Rp();
651 template <class _Arg>
652 _LIBCPP_AVAILABILITY_FUTURE
654 __assoc_state<_Rp>::set_value(_Arg&& __arg)
656 unique_lock<mutex> __lk(this->__mut_);
657 if (this->__has_value())
658 __throw_future_error(future_errc::promise_already_satisfied);
659 ::new ((void*)&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
660 this->__state_ |= base::__constructed | base::ready;
665 template <class _Arg>
667 __assoc_state<_Rp>::set_value_at_thread_exit(_Arg&& __arg)
669 unique_lock<mutex> __lk(this->__mut_);
670 if (this->__has_value())
671 __throw_future_error(future_errc::promise_already_satisfied);
672 ::new ((void*)&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
673 this->__state_ |= base::__constructed;
674 __thread_local_data()->__make_ready_at_thread_exit(this);
679 __assoc_state<_Rp>::move()
681 unique_lock<mutex> __lk(this->__mut_);
682 this->__sub_wait(__lk);
683 if (this->__exception_ != nullptr)
684 rethrow_exception(this->__exception_);
685 return _VSTD::move(*reinterpret_cast<_Rp*>(&__value_));
689 typename add_lvalue_reference<_Rp>::type
690 __assoc_state<_Rp>::copy()
692 unique_lock<mutex> __lk(this->__mut_);
693 this->__sub_wait(__lk);
694 if (this->__exception_ != nullptr)
695 rethrow_exception(this->__exception_);
696 return *reinterpret_cast<_Rp*>(&__value_);
700 class _LIBCPP_AVAILABILITY_FUTURE __assoc_state<_Rp&>
701 : public __assoc_sub_state
703 typedef __assoc_sub_state base;
708 virtual void __on_zero_shared() _NOEXCEPT;
711 void set_value(_Rp& __arg);
712 void set_value_at_thread_exit(_Rp& __arg);
719 __assoc_state<_Rp&>::__on_zero_shared() _NOEXCEPT
726 __assoc_state<_Rp&>::set_value(_Rp& __arg)
728 unique_lock<mutex> __lk(this->__mut_);
729 if (this->__has_value())
730 __throw_future_error(future_errc::promise_already_satisfied);
731 __value_ = _VSTD::addressof(__arg);
732 this->__state_ |= base::__constructed | base::ready;
738 __assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg)
740 unique_lock<mutex> __lk(this->__mut_);
741 if (this->__has_value())
742 __throw_future_error(future_errc::promise_already_satisfied);
743 __value_ = _VSTD::addressof(__arg);
744 this->__state_ |= base::__constructed;
745 __thread_local_data()->__make_ready_at_thread_exit(this);
750 __assoc_state<_Rp&>::copy()
752 unique_lock<mutex> __lk(this->__mut_);
753 this->__sub_wait(__lk);
754 if (this->__exception_ != nullptr)
755 rethrow_exception(this->__exception_);
759 template <class _Rp, class _Alloc>
760 class _LIBCPP_AVAILABILITY_FUTURE __assoc_state_alloc
761 : public __assoc_state<_Rp>
763 typedef __assoc_state<_Rp> base;
766 virtual void __on_zero_shared() _NOEXCEPT;
768 _LIBCPP_INLINE_VISIBILITY
769 explicit __assoc_state_alloc(const _Alloc& __a)
773 template <class _Rp, class _Alloc>
775 __assoc_state_alloc<_Rp, _Alloc>::__on_zero_shared() _NOEXCEPT
777 if (this->__state_ & base::__constructed)
778 reinterpret_cast<_Rp*>(_VSTD::addressof(this->__value_))->~_Rp();
779 typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al;
780 typedef allocator_traits<_Al> _ATraits;
781 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
783 this->~__assoc_state_alloc();
784 __a.deallocate(_PTraits::pointer_to(*this), 1);
787 template <class _Rp, class _Alloc>
788 class _LIBCPP_AVAILABILITY_FUTURE __assoc_state_alloc<_Rp&, _Alloc>
789 : public __assoc_state<_Rp&>
791 typedef __assoc_state<_Rp&> base;
794 virtual void __on_zero_shared() _NOEXCEPT;
796 _LIBCPP_INLINE_VISIBILITY
797 explicit __assoc_state_alloc(const _Alloc& __a)
801 template <class _Rp, class _Alloc>
803 __assoc_state_alloc<_Rp&, _Alloc>::__on_zero_shared() _NOEXCEPT
805 typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al;
806 typedef allocator_traits<_Al> _ATraits;
807 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
809 this->~__assoc_state_alloc();
810 __a.deallocate(_PTraits::pointer_to(*this), 1);
813 template <class _Alloc>
814 class _LIBCPP_AVAILABILITY_FUTURE __assoc_sub_state_alloc
815 : public __assoc_sub_state
817 typedef __assoc_sub_state base;
820 virtual void __on_zero_shared() _NOEXCEPT;
822 _LIBCPP_INLINE_VISIBILITY
823 explicit __assoc_sub_state_alloc(const _Alloc& __a)
827 template <class _Alloc>
829 __assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT
831 typedef typename __allocator_traits_rebind<_Alloc, __assoc_sub_state_alloc>::type _Al;
832 typedef allocator_traits<_Al> _ATraits;
833 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
835 this->~__assoc_sub_state_alloc();
836 __a.deallocate(_PTraits::pointer_to(*this), 1);
839 template <class _Rp, class _Fp>
840 class _LIBCPP_AVAILABILITY_FUTURE __deferred_assoc_state
841 : public __assoc_state<_Rp>
843 typedef __assoc_state<_Rp> base;
848 _LIBCPP_INLINE_VISIBILITY
849 explicit __deferred_assoc_state(_Fp&& __f);
851 virtual void __execute();
854 template <class _Rp, class _Fp>
856 __deferred_assoc_state<_Rp, _Fp>::__deferred_assoc_state(_Fp&& __f)
857 : __func_(_VSTD::forward<_Fp>(__f))
859 this->__set_deferred();
862 template <class _Rp, class _Fp>
864 __deferred_assoc_state<_Rp, _Fp>::__execute()
866 #ifndef _LIBCPP_NO_EXCEPTIONS
869 #endif // _LIBCPP_NO_EXCEPTIONS
870 this->set_value(__func_());
871 #ifndef _LIBCPP_NO_EXCEPTIONS
875 this->set_exception(current_exception());
877 #endif // _LIBCPP_NO_EXCEPTIONS
881 class _LIBCPP_AVAILABILITY_FUTURE __deferred_assoc_state<void, _Fp>
882 : public __assoc_sub_state
884 typedef __assoc_sub_state base;
889 _LIBCPP_INLINE_VISIBILITY
890 explicit __deferred_assoc_state(_Fp&& __f);
892 virtual void __execute();
897 __deferred_assoc_state<void, _Fp>::__deferred_assoc_state(_Fp&& __f)
898 : __func_(_VSTD::forward<_Fp>(__f))
900 this->__set_deferred();
905 __deferred_assoc_state<void, _Fp>::__execute()
907 #ifndef _LIBCPP_NO_EXCEPTIONS
910 #endif // _LIBCPP_NO_EXCEPTIONS
913 #ifndef _LIBCPP_NO_EXCEPTIONS
917 this->set_exception(current_exception());
919 #endif // _LIBCPP_NO_EXCEPTIONS
922 template <class _Rp, class _Fp>
923 class _LIBCPP_AVAILABILITY_FUTURE __async_assoc_state
924 : public __assoc_state<_Rp>
926 typedef __assoc_state<_Rp> base;
930 virtual void __on_zero_shared() _NOEXCEPT;
932 _LIBCPP_INLINE_VISIBILITY
933 explicit __async_assoc_state(_Fp&& __f);
935 virtual void __execute();
938 template <class _Rp, class _Fp>
940 __async_assoc_state<_Rp, _Fp>::__async_assoc_state(_Fp&& __f)
941 : __func_(_VSTD::forward<_Fp>(__f))
945 template <class _Rp, class _Fp>
947 __async_assoc_state<_Rp, _Fp>::__execute()
949 #ifndef _LIBCPP_NO_EXCEPTIONS
952 #endif // _LIBCPP_NO_EXCEPTIONS
953 this->set_value(__func_());
954 #ifndef _LIBCPP_NO_EXCEPTIONS
958 this->set_exception(current_exception());
960 #endif // _LIBCPP_NO_EXCEPTIONS
963 template <class _Rp, class _Fp>
965 __async_assoc_state<_Rp, _Fp>::__on_zero_shared() _NOEXCEPT
968 base::__on_zero_shared();
972 class _LIBCPP_AVAILABILITY_FUTURE __async_assoc_state<void, _Fp>
973 : public __assoc_sub_state
975 typedef __assoc_sub_state base;
979 virtual void __on_zero_shared() _NOEXCEPT;
981 _LIBCPP_INLINE_VISIBILITY
982 explicit __async_assoc_state(_Fp&& __f);
984 virtual void __execute();
989 __async_assoc_state<void, _Fp>::__async_assoc_state(_Fp&& __f)
990 : __func_(_VSTD::forward<_Fp>(__f))
996 __async_assoc_state<void, _Fp>::__execute()
998 #ifndef _LIBCPP_NO_EXCEPTIONS
1001 #endif // _LIBCPP_NO_EXCEPTIONS
1004 #ifndef _LIBCPP_NO_EXCEPTIONS
1008 this->set_exception(current_exception());
1010 #endif // _LIBCPP_NO_EXCEPTIONS
1013 template <class _Fp>
1015 __async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT
1018 base::__on_zero_shared();
1021 template <class _Rp> class _LIBCPP_TEMPLATE_VIS promise;
1022 template <class _Rp> class _LIBCPP_TEMPLATE_VIS shared_future;
1026 template <class _Rp> class _LIBCPP_TEMPLATE_VIS future;
1028 template <class _Rp, class _Fp>
1029 _LIBCPP_INLINE_VISIBILITY future<_Rp>
1030 __make_deferred_assoc_state(_Fp&& __f);
1032 template <class _Rp, class _Fp>
1033 _LIBCPP_INLINE_VISIBILITY future<_Rp>
1034 __make_async_assoc_state(_Fp&& __f);
1036 template <class _Rp>
1037 class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE future
1039 __assoc_state<_Rp>* __state_;
1041 explicit future(__assoc_state<_Rp>* __state);
1043 template <class> friend class promise;
1044 template <class> friend class shared_future;
1046 template <class _R1, class _Fp>
1047 friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
1048 template <class _R1, class _Fp>
1049 friend future<_R1> __make_async_assoc_state(_Fp&& __f);
1052 _LIBCPP_INLINE_VISIBILITY
1053 future() _NOEXCEPT : __state_(nullptr) {}
1054 _LIBCPP_INLINE_VISIBILITY
1055 future(future&& __rhs) _NOEXCEPT
1056 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1057 future(const future&) = delete;
1058 future& operator=(const future&) = delete;
1059 _LIBCPP_INLINE_VISIBILITY
1060 future& operator=(future&& __rhs) _NOEXCEPT
1062 future(_VSTD::move(__rhs)).swap(*this);
1067 _LIBCPP_INLINE_VISIBILITY
1068 shared_future<_Rp> share() _NOEXCEPT;
1070 // retrieving the value
1073 _LIBCPP_INLINE_VISIBILITY
1074 void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1076 // functions to check state
1077 _LIBCPP_INLINE_VISIBILITY
1078 bool valid() const _NOEXCEPT {return __state_ != nullptr;}
1080 _LIBCPP_INLINE_VISIBILITY
1081 void wait() const {__state_->wait();}
1082 template <class _Rep, class _Period>
1083 _LIBCPP_INLINE_VISIBILITY
1085 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
1086 {return __state_->wait_for(__rel_time);}
1087 template <class _Clock, class _Duration>
1088 _LIBCPP_INLINE_VISIBILITY
1090 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
1091 {return __state_->wait_until(__abs_time);}
1094 template <class _Rp>
1095 future<_Rp>::future(__assoc_state<_Rp>* __state)
1098 __state_->__attach_future();
1101 struct __release_shared_count
1103 void operator()(__shared_count* p) {p->__release_shared();}
1106 template <class _Rp>
1107 future<_Rp>::~future()
1110 __state_->__release_shared();
1113 template <class _Rp>
1117 unique_ptr<__shared_count, __release_shared_count> __(__state_);
1118 __assoc_state<_Rp>* __s = __state_;
1123 template <class _Rp>
1124 class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE future<_Rp&>
1126 __assoc_state<_Rp&>* __state_;
1128 explicit future(__assoc_state<_Rp&>* __state);
1130 template <class> friend class promise;
1131 template <class> friend class shared_future;
1133 template <class _R1, class _Fp>
1134 friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
1135 template <class _R1, class _Fp>
1136 friend future<_R1> __make_async_assoc_state(_Fp&& __f);
1139 _LIBCPP_INLINE_VISIBILITY
1140 future() _NOEXCEPT : __state_(nullptr) {}
1141 _LIBCPP_INLINE_VISIBILITY
1142 future(future&& __rhs) _NOEXCEPT
1143 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1144 future(const future&) = delete;
1145 future& operator=(const future&) = delete;
1146 _LIBCPP_INLINE_VISIBILITY
1147 future& operator=(future&& __rhs) _NOEXCEPT
1149 future(_VSTD::move(__rhs)).swap(*this);
1154 _LIBCPP_INLINE_VISIBILITY
1155 shared_future<_Rp&> share() _NOEXCEPT;
1157 // retrieving the value
1160 _LIBCPP_INLINE_VISIBILITY
1161 void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1163 // functions to check state
1164 _LIBCPP_INLINE_VISIBILITY
1165 bool valid() const _NOEXCEPT {return __state_ != nullptr;}
1167 _LIBCPP_INLINE_VISIBILITY
1168 void wait() const {__state_->wait();}
1169 template <class _Rep, class _Period>
1170 _LIBCPP_INLINE_VISIBILITY
1172 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
1173 {return __state_->wait_for(__rel_time);}
1174 template <class _Clock, class _Duration>
1175 _LIBCPP_INLINE_VISIBILITY
1177 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
1178 {return __state_->wait_until(__abs_time);}
1181 template <class _Rp>
1182 future<_Rp&>::future(__assoc_state<_Rp&>* __state)
1185 __state_->__attach_future();
1188 template <class _Rp>
1189 future<_Rp&>::~future()
1192 __state_->__release_shared();
1195 template <class _Rp>
1199 unique_ptr<__shared_count, __release_shared_count> __(__state_);
1200 __assoc_state<_Rp&>* __s = __state_;
1206 class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE future<void>
1208 __assoc_sub_state* __state_;
1210 explicit future(__assoc_sub_state* __state);
1212 template <class> friend class promise;
1213 template <class> friend class shared_future;
1215 template <class _R1, class _Fp>
1216 friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
1217 template <class _R1, class _Fp>
1218 friend future<_R1> __make_async_assoc_state(_Fp&& __f);
1221 _LIBCPP_INLINE_VISIBILITY
1222 future() _NOEXCEPT : __state_(nullptr) {}
1223 _LIBCPP_INLINE_VISIBILITY
1224 future(future&& __rhs) _NOEXCEPT
1225 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1226 future(const future&) = delete;
1227 future& operator=(const future&) = delete;
1228 _LIBCPP_INLINE_VISIBILITY
1229 future& operator=(future&& __rhs) _NOEXCEPT
1231 future(_VSTD::move(__rhs)).swap(*this);
1236 _LIBCPP_INLINE_VISIBILITY
1237 shared_future<void> share() _NOEXCEPT;
1239 // retrieving the value
1242 _LIBCPP_INLINE_VISIBILITY
1243 void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1245 // functions to check state
1246 _LIBCPP_INLINE_VISIBILITY
1247 bool valid() const _NOEXCEPT {return __state_ != nullptr;}
1249 _LIBCPP_INLINE_VISIBILITY
1250 void wait() const {__state_->wait();}
1251 template <class _Rep, class _Period>
1252 _LIBCPP_INLINE_VISIBILITY
1254 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
1255 {return __state_->wait_for(__rel_time);}
1256 template <class _Clock, class _Duration>
1257 _LIBCPP_INLINE_VISIBILITY
1259 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
1260 {return __state_->wait_until(__abs_time);}
1263 template <class _Rp>
1264 inline _LIBCPP_INLINE_VISIBILITY
1266 swap(future<_Rp>& __x, future<_Rp>& __y) _NOEXCEPT
1273 template <class _Callable> class packaged_task;
1275 template <class _Rp>
1276 class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE promise
1278 __assoc_state<_Rp>* __state_;
1280 _LIBCPP_INLINE_VISIBILITY
1281 explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
1283 template <class> friend class packaged_task;
1286 template <class _Alloc>
1287 promise(allocator_arg_t, const _Alloc& __a);
1288 _LIBCPP_INLINE_VISIBILITY
1289 promise(promise&& __rhs) _NOEXCEPT
1290 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1291 promise(const promise& __rhs) = delete;
1295 _LIBCPP_INLINE_VISIBILITY
1296 promise& operator=(promise&& __rhs) _NOEXCEPT
1298 promise(_VSTD::move(__rhs)).swap(*this);
1301 promise& operator=(const promise& __rhs) = delete;
1303 _LIBCPP_INLINE_VISIBILITY
1304 void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1306 // retrieving the result
1307 future<_Rp> get_future();
1309 // setting the result
1310 void set_value(const _Rp& __r);
1311 void set_value(_Rp&& __r);
1312 void set_exception(exception_ptr __p);
1314 // setting the result with deferred notification
1315 void set_value_at_thread_exit(const _Rp& __r);
1316 void set_value_at_thread_exit(_Rp&& __r);
1317 void set_exception_at_thread_exit(exception_ptr __p);
1320 template <class _Rp>
1321 promise<_Rp>::promise()
1322 : __state_(new __assoc_state<_Rp>)
1326 template <class _Rp>
1327 template <class _Alloc>
1328 promise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0)
1330 typedef __assoc_state_alloc<_Rp, _Alloc> _State;
1331 typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2;
1332 typedef __allocator_destructor<_A2> _D2;
1334 unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1));
1335 ::new ((void*)_VSTD::addressof(*__hold.get())) _State(__a0);
1336 __state_ = _VSTD::addressof(*__hold.release());
1339 template <class _Rp>
1340 promise<_Rp>::~promise()
1344 if (!__state_->__has_value() && __state_->use_count() > 1)
1345 __state_->set_exception(make_exception_ptr(
1346 future_error(make_error_code(future_errc::broken_promise))
1348 __state_->__release_shared();
1352 template <class _Rp>
1354 promise<_Rp>::get_future()
1356 if (__state_ == nullptr)
1357 __throw_future_error(future_errc::no_state);
1358 return future<_Rp>(__state_);
1361 template <class _Rp>
1363 promise<_Rp>::set_value(const _Rp& __r)
1365 if (__state_ == nullptr)
1366 __throw_future_error(future_errc::no_state);
1367 __state_->set_value(__r);
1370 template <class _Rp>
1372 promise<_Rp>::set_value(_Rp&& __r)
1374 if (__state_ == nullptr)
1375 __throw_future_error(future_errc::no_state);
1376 __state_->set_value(_VSTD::move(__r));
1379 template <class _Rp>
1381 promise<_Rp>::set_exception(exception_ptr __p)
1383 _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception: received nullptr" );
1384 if (__state_ == nullptr)
1385 __throw_future_error(future_errc::no_state);
1386 __state_->set_exception(__p);
1389 template <class _Rp>
1391 promise<_Rp>::set_value_at_thread_exit(const _Rp& __r)
1393 if (__state_ == nullptr)
1394 __throw_future_error(future_errc::no_state);
1395 __state_->set_value_at_thread_exit(__r);
1398 template <class _Rp>
1400 promise<_Rp>::set_value_at_thread_exit(_Rp&& __r)
1402 if (__state_ == nullptr)
1403 __throw_future_error(future_errc::no_state);
1404 __state_->set_value_at_thread_exit(_VSTD::move(__r));
1407 template <class _Rp>
1409 promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p)
1411 _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception_at_thread_exit: received nullptr" );
1412 if (__state_ == nullptr)
1413 __throw_future_error(future_errc::no_state);
1414 __state_->set_exception_at_thread_exit(__p);
1419 template <class _Rp>
1420 class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE promise<_Rp&>
1422 __assoc_state<_Rp&>* __state_;
1424 _LIBCPP_INLINE_VISIBILITY
1425 explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
1427 template <class> friend class packaged_task;
1431 template <class _Allocator>
1432 promise(allocator_arg_t, const _Allocator& __a);
1433 _LIBCPP_INLINE_VISIBILITY
1434 promise(promise&& __rhs) _NOEXCEPT
1435 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1436 promise(const promise& __rhs) = delete;
1440 _LIBCPP_INLINE_VISIBILITY
1441 promise& operator=(promise&& __rhs) _NOEXCEPT
1443 promise(_VSTD::move(__rhs)).swap(*this);
1446 promise& operator=(const promise& __rhs) = delete;
1448 _LIBCPP_INLINE_VISIBILITY
1449 void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1451 // retrieving the result
1452 future<_Rp&> get_future();
1454 // setting the result
1455 void set_value(_Rp& __r);
1456 void set_exception(exception_ptr __p);
1458 // setting the result with deferred notification
1459 void set_value_at_thread_exit(_Rp&);
1460 void set_exception_at_thread_exit(exception_ptr __p);
1463 template <class _Rp>
1464 promise<_Rp&>::promise()
1465 : __state_(new __assoc_state<_Rp&>)
1469 template <class _Rp>
1470 template <class _Alloc>
1471 promise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0)
1473 typedef __assoc_state_alloc<_Rp&, _Alloc> _State;
1474 typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2;
1475 typedef __allocator_destructor<_A2> _D2;
1477 unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1));
1478 ::new ((void*)_VSTD::addressof(*__hold.get())) _State(__a0);
1479 __state_ = _VSTD::addressof(*__hold.release());
1482 template <class _Rp>
1483 promise<_Rp&>::~promise()
1487 if (!__state_->__has_value() && __state_->use_count() > 1)
1488 __state_->set_exception(make_exception_ptr(
1489 future_error(make_error_code(future_errc::broken_promise))
1491 __state_->__release_shared();
1495 template <class _Rp>
1497 promise<_Rp&>::get_future()
1499 if (__state_ == nullptr)
1500 __throw_future_error(future_errc::no_state);
1501 return future<_Rp&>(__state_);
1504 template <class _Rp>
1506 promise<_Rp&>::set_value(_Rp& __r)
1508 if (__state_ == nullptr)
1509 __throw_future_error(future_errc::no_state);
1510 __state_->set_value(__r);
1513 template <class _Rp>
1515 promise<_Rp&>::set_exception(exception_ptr __p)
1517 _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception: received nullptr" );
1518 if (__state_ == nullptr)
1519 __throw_future_error(future_errc::no_state);
1520 __state_->set_exception(__p);
1523 template <class _Rp>
1525 promise<_Rp&>::set_value_at_thread_exit(_Rp& __r)
1527 if (__state_ == nullptr)
1528 __throw_future_error(future_errc::no_state);
1529 __state_->set_value_at_thread_exit(__r);
1532 template <class _Rp>
1534 promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p)
1536 _LIBCPP_ASSERT( __p != nullptr, "promise::set_exception_at_thread_exit: received nullptr" );
1537 if (__state_ == nullptr)
1538 __throw_future_error(future_errc::no_state);
1539 __state_->set_exception_at_thread_exit(__p);
1545 class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE promise<void>
1547 __assoc_sub_state* __state_;
1549 _LIBCPP_INLINE_VISIBILITY
1550 explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
1552 template <class> friend class packaged_task;
1556 template <class _Allocator>
1557 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1558 promise(allocator_arg_t, const _Allocator& __a);
1559 _LIBCPP_INLINE_VISIBILITY
1560 promise(promise&& __rhs) _NOEXCEPT
1561 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1562 promise(const promise& __rhs) = delete;
1566 _LIBCPP_INLINE_VISIBILITY
1567 promise& operator=(promise&& __rhs) _NOEXCEPT
1569 promise(_VSTD::move(__rhs)).swap(*this);
1572 promise& operator=(const promise& __rhs) = delete;
1574 _LIBCPP_INLINE_VISIBILITY
1575 void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
1577 // retrieving the result
1578 future<void> get_future();
1580 // setting the result
1582 void set_exception(exception_ptr __p);
1584 // setting the result with deferred notification
1585 void set_value_at_thread_exit();
1586 void set_exception_at_thread_exit(exception_ptr __p);
1589 template <class _Alloc>
1590 promise<void>::promise(allocator_arg_t, const _Alloc& __a0)
1592 typedef __assoc_sub_state_alloc<_Alloc> _State;
1593 typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2;
1594 typedef __allocator_destructor<_A2> _D2;
1596 unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1));
1597 ::new ((void*)_VSTD::addressof(*__hold.get())) _State(__a0);
1598 __state_ = _VSTD::addressof(*__hold.release());
1601 template <class _Rp>
1602 inline _LIBCPP_INLINE_VISIBILITY
1604 swap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT
1609 template <class _Rp, class _Alloc>
1610 struct _LIBCPP_TEMPLATE_VIS uses_allocator<promise<_Rp>, _Alloc>
1611 : public true_type {};
1615 template<class _Fp> class __packaged_task_base;
1617 template<class _Rp, class ..._ArgTypes>
1618 class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_base<_Rp(_ArgTypes...)>
1620 __packaged_task_base(const __packaged_task_base&);
1621 __packaged_task_base& operator=(const __packaged_task_base&);
1623 _LIBCPP_INLINE_VISIBILITY
1624 __packaged_task_base() {}
1625 _LIBCPP_INLINE_VISIBILITY
1626 virtual ~__packaged_task_base() {}
1627 virtual void __move_to(__packaged_task_base*) _NOEXCEPT = 0;
1628 virtual void destroy() = 0;
1629 virtual void destroy_deallocate() = 0;
1630 virtual _Rp operator()(_ArgTypes&& ...) = 0;
1633 template<class _FD, class _Alloc, class _FB> class __packaged_task_func;
1635 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1636 class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1637 : public __packaged_task_base<_Rp(_ArgTypes...)>
1639 __compressed_pair<_Fp, _Alloc> __f_;
1641 _LIBCPP_INLINE_VISIBILITY
1642 explicit __packaged_task_func(const _Fp& __f) : __f_(__f, __default_init_tag()) {}
1643 _LIBCPP_INLINE_VISIBILITY
1644 explicit __packaged_task_func(_Fp&& __f) : __f_(_VSTD::move(__f), __default_init_tag()) {}
1645 _LIBCPP_INLINE_VISIBILITY
1646 __packaged_task_func(const _Fp& __f, const _Alloc& __a)
1648 _LIBCPP_INLINE_VISIBILITY
1649 __packaged_task_func(_Fp&& __f, const _Alloc& __a)
1650 : __f_(_VSTD::move(__f), __a) {}
1651 virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*) _NOEXCEPT;
1652 virtual void destroy();
1653 virtual void destroy_deallocate();
1654 virtual _Rp operator()(_ArgTypes&& ... __args);
1657 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1659 __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to(
1660 __packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT
1662 ::new ((void*)__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second()));
1665 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1667 __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy()
1669 __f_.~__compressed_pair<_Fp, _Alloc>();
1672 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1674 __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate()
1676 typedef typename __allocator_traits_rebind<_Alloc, __packaged_task_func>::type _Ap;
1677 typedef allocator_traits<_Ap> _ATraits;
1678 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
1679 _Ap __a(__f_.second());
1680 __f_.~__compressed_pair<_Fp, _Alloc>();
1681 __a.deallocate(_PTraits::pointer_to(*this), 1);
1684 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1686 __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1688 return _VSTD::__invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
1691 template <class _Callable> class __packaged_task_function;
1693 template<class _Rp, class ..._ArgTypes>
1694 class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_function<_Rp(_ArgTypes...)>
1696 typedef __packaged_task_base<_Rp(_ArgTypes...)> __base;
1698 _LIBCPP_INLINE_VISIBILITY _LIBCPP_NO_CFI
1699 __base* __get_buf() { return (__base*)&__buf_; }
1701 typename aligned_storage<3*sizeof(void*)>::type __buf_;
1705 typedef _Rp result_type;
1707 // construct/copy/destroy:
1708 _LIBCPP_INLINE_VISIBILITY
1709 __packaged_task_function() _NOEXCEPT : __f_(nullptr) {}
1711 __packaged_task_function(_Fp&& __f);
1712 template<class _Fp, class _Alloc>
1713 __packaged_task_function(allocator_arg_t, const _Alloc& __a, _Fp&& __f);
1715 __packaged_task_function(__packaged_task_function&&) _NOEXCEPT;
1716 __packaged_task_function& operator=(__packaged_task_function&&) _NOEXCEPT;
1718 __packaged_task_function(const __packaged_task_function&) = delete;
1719 __packaged_task_function& operator=(const __packaged_task_function&) = delete;
1721 ~__packaged_task_function();
1723 void swap(__packaged_task_function&) _NOEXCEPT;
1725 _LIBCPP_INLINE_VISIBILITY
1726 _Rp operator()(_ArgTypes...) const;
1729 template<class _Rp, class ..._ArgTypes>
1730 __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f) _NOEXCEPT
1732 if (__f.__f_ == nullptr)
1734 else if (__f.__f_ == __f.__get_buf())
1736 __f.__f_->__move_to(__get_buf());
1737 __f_ = (__base*)&__buf_;
1746 template<class _Rp, class ..._ArgTypes>
1747 template <class _Fp>
1748 __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f)
1751 typedef typename remove_reference<typename decay<_Fp>::type>::type _FR;
1752 typedef __packaged_task_func<_FR, allocator<_FR>, _Rp(_ArgTypes...)> _FF;
1753 if (sizeof(_FF) <= sizeof(__buf_))
1755 ::new ((void*)&__buf_) _FF(_VSTD::forward<_Fp>(__f));
1756 __f_ = (__base*)&__buf_;
1760 typedef allocator<_FF> _Ap;
1762 typedef __allocator_destructor<_Ap> _Dp;
1763 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1764 ::new ((void*)__hold.get()) _FF(_VSTD::forward<_Fp>(__f), allocator<_FR>(__a));
1765 __f_ = __hold.release();
1769 template<class _Rp, class ..._ArgTypes>
1770 template <class _Fp, class _Alloc>
1771 __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(
1772 allocator_arg_t, const _Alloc& __a0, _Fp&& __f)
1775 typedef typename remove_reference<typename decay<_Fp>::type>::type _FR;
1776 typedef __packaged_task_func<_FR, _Alloc, _Rp(_ArgTypes...)> _FF;
1777 if (sizeof(_FF) <= sizeof(__buf_))
1779 __f_ = (__base*)&__buf_;
1780 ::new ((void*)__f_) _FF(_VSTD::forward<_Fp>(__f));
1784 typedef typename __allocator_traits_rebind<_Alloc, _FF>::type _Ap;
1786 typedef __allocator_destructor<_Ap> _Dp;
1787 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1788 ::new ((void*)_VSTD::addressof(*__hold.get()))
1789 _FF(_VSTD::forward<_Fp>(__f), _Alloc(__a));
1790 __f_ = _VSTD::addressof(*__hold.release());
1794 template<class _Rp, class ..._ArgTypes>
1795 __packaged_task_function<_Rp(_ArgTypes...)>&
1796 __packaged_task_function<_Rp(_ArgTypes...)>::operator=(__packaged_task_function&& __f) _NOEXCEPT
1798 if (__f_ == __get_buf())
1801 __f_->destroy_deallocate();
1803 if (__f.__f_ == nullptr)
1805 else if (__f.__f_ == __f.__get_buf())
1807 __f.__f_->__move_to(__get_buf());
1818 template<class _Rp, class ..._ArgTypes>
1819 __packaged_task_function<_Rp(_ArgTypes...)>::~__packaged_task_function()
1821 if (__f_ == __get_buf())
1824 __f_->destroy_deallocate();
1827 template<class _Rp, class ..._ArgTypes>
1830 __packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f) _NOEXCEPT
1832 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1834 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1835 __base* __t = (__base*)&__tempbuf;
1836 __f_->__move_to(__t);
1839 __f.__f_->__move_to((__base*)&__buf_);
1840 __f.__f_->destroy();
1842 __f_ = (__base*)&__buf_;
1843 __t->__move_to((__base*)&__f.__buf_);
1845 __f.__f_ = (__base*)&__f.__buf_;
1847 else if (__f_ == (__base*)&__buf_)
1849 __f_->__move_to((__base*)&__f.__buf_);
1852 __f.__f_ = (__base*)&__f.__buf_;
1854 else if (__f.__f_ == (__base*)&__f.__buf_)
1856 __f.__f_->__move_to((__base*)&__buf_);
1857 __f.__f_->destroy();
1859 __f_ = (__base*)&__buf_;
1862 _VSTD::swap(__f_, __f.__f_);
1865 template<class _Rp, class ..._ArgTypes>
1868 __packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1870 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
1873 template<class _Rp, class ..._ArgTypes>
1874 class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE packaged_task<_Rp(_ArgTypes...)>
1877 typedef _Rp result_type; // extension
1880 __packaged_task_function<result_type(_ArgTypes...)> __f_;
1881 promise<result_type> __p_;
1884 // construction and destruction
1885 _LIBCPP_INLINE_VISIBILITY
1886 packaged_task() _NOEXCEPT : __p_(nullptr) {}
1887 template <class _Fp,
1888 class = typename enable_if
1891 typename __uncvref<_Fp>::type,
1896 _LIBCPP_INLINE_VISIBILITY
1897 explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
1898 template <class _Fp, class _Allocator,
1899 class = typename enable_if
1902 typename __uncvref<_Fp>::type,
1907 _LIBCPP_INLINE_VISIBILITY
1908 packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
1909 : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
1910 __p_(allocator_arg, __a) {}
1911 // ~packaged_task() = default;
1914 packaged_task(const packaged_task&) = delete;
1915 packaged_task& operator=(const packaged_task&) = delete;
1918 _LIBCPP_INLINE_VISIBILITY
1919 packaged_task(packaged_task&& __other) _NOEXCEPT
1920 : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
1921 _LIBCPP_INLINE_VISIBILITY
1922 packaged_task& operator=(packaged_task&& __other) _NOEXCEPT
1924 __f_ = _VSTD::move(__other.__f_);
1925 __p_ = _VSTD::move(__other.__p_);
1928 _LIBCPP_INLINE_VISIBILITY
1929 void swap(packaged_task& __other) _NOEXCEPT
1931 __f_.swap(__other.__f_);
1932 __p_.swap(__other.__p_);
1935 _LIBCPP_INLINE_VISIBILITY
1936 bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;}
1939 _LIBCPP_INLINE_VISIBILITY
1940 future<result_type> get_future() {return __p_.get_future();}
1943 void operator()(_ArgTypes... __args);
1944 void make_ready_at_thread_exit(_ArgTypes... __args);
1949 template<class _Rp, class ..._ArgTypes>
1951 packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args)
1953 if (__p_.__state_ == nullptr)
1954 __throw_future_error(future_errc::no_state);
1955 if (__p_.__state_->__has_value())
1956 __throw_future_error(future_errc::promise_already_satisfied);
1957 #ifndef _LIBCPP_NO_EXCEPTIONS
1960 #endif // _LIBCPP_NO_EXCEPTIONS
1961 __p_.set_value(__f_(_VSTD::forward<_ArgTypes>(__args)...));
1962 #ifndef _LIBCPP_NO_EXCEPTIONS
1966 __p_.set_exception(current_exception());
1968 #endif // _LIBCPP_NO_EXCEPTIONS
1971 template<class _Rp, class ..._ArgTypes>
1973 packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
1975 if (__p_.__state_ == nullptr)
1976 __throw_future_error(future_errc::no_state);
1977 if (__p_.__state_->__has_value())
1978 __throw_future_error(future_errc::promise_already_satisfied);
1979 #ifndef _LIBCPP_NO_EXCEPTIONS
1982 #endif // _LIBCPP_NO_EXCEPTIONS
1983 __p_.set_value_at_thread_exit(__f_(_VSTD::forward<_ArgTypes>(__args)...));
1984 #ifndef _LIBCPP_NO_EXCEPTIONS
1988 __p_.set_exception_at_thread_exit(current_exception());
1990 #endif // _LIBCPP_NO_EXCEPTIONS
1993 template<class _Rp, class ..._ArgTypes>
1995 packaged_task<_Rp(_ArgTypes...)>::reset()
1998 __throw_future_error(future_errc::no_state);
1999 __p_ = promise<result_type>();
2002 template<class ..._ArgTypes>
2003 class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE packaged_task<void(_ArgTypes...)>
2006 typedef void result_type; // extension
2009 __packaged_task_function<result_type(_ArgTypes...)> __f_;
2010 promise<result_type> __p_;
2013 // construction and destruction
2014 _LIBCPP_INLINE_VISIBILITY
2015 packaged_task() _NOEXCEPT : __p_(nullptr) {}
2016 template <class _Fp,
2017 class = typename enable_if
2020 typename __uncvref<_Fp>::type,
2025 _LIBCPP_INLINE_VISIBILITY
2026 explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
2027 template <class _Fp, class _Allocator,
2028 class = typename enable_if
2031 typename __uncvref<_Fp>::type,
2036 _LIBCPP_INLINE_VISIBILITY
2037 packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
2038 : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
2039 __p_(allocator_arg, __a) {}
2040 // ~packaged_task() = default;
2043 packaged_task(const packaged_task&) = delete;
2044 packaged_task& operator=(const packaged_task&) = delete;
2047 _LIBCPP_INLINE_VISIBILITY
2048 packaged_task(packaged_task&& __other) _NOEXCEPT
2049 : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
2050 _LIBCPP_INLINE_VISIBILITY
2051 packaged_task& operator=(packaged_task&& __other) _NOEXCEPT
2053 __f_ = _VSTD::move(__other.__f_);
2054 __p_ = _VSTD::move(__other.__p_);
2057 _LIBCPP_INLINE_VISIBILITY
2058 void swap(packaged_task& __other) _NOEXCEPT
2060 __f_.swap(__other.__f_);
2061 __p_.swap(__other.__p_);
2064 _LIBCPP_INLINE_VISIBILITY
2065 bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;}
2068 _LIBCPP_INLINE_VISIBILITY
2069 future<result_type> get_future() {return __p_.get_future();}
2072 void operator()(_ArgTypes... __args);
2073 void make_ready_at_thread_exit(_ArgTypes... __args);
2078 template<class ..._ArgTypes>
2080 packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args)
2082 if (__p_.__state_ == nullptr)
2083 __throw_future_error(future_errc::no_state);
2084 if (__p_.__state_->__has_value())
2085 __throw_future_error(future_errc::promise_already_satisfied);
2086 #ifndef _LIBCPP_NO_EXCEPTIONS
2089 #endif // _LIBCPP_NO_EXCEPTIONS
2090 __f_(_VSTD::forward<_ArgTypes>(__args)...);
2092 #ifndef _LIBCPP_NO_EXCEPTIONS
2096 __p_.set_exception(current_exception());
2098 #endif // _LIBCPP_NO_EXCEPTIONS
2101 template<class ..._ArgTypes>
2103 packaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
2105 if (__p_.__state_ == nullptr)
2106 __throw_future_error(future_errc::no_state);
2107 if (__p_.__state_->__has_value())
2108 __throw_future_error(future_errc::promise_already_satisfied);
2109 #ifndef _LIBCPP_NO_EXCEPTIONS
2112 #endif // _LIBCPP_NO_EXCEPTIONS
2113 __f_(_VSTD::forward<_ArgTypes>(__args)...);
2114 __p_.set_value_at_thread_exit();
2115 #ifndef _LIBCPP_NO_EXCEPTIONS
2119 __p_.set_exception_at_thread_exit(current_exception());
2121 #endif // _LIBCPP_NO_EXCEPTIONS
2124 template<class ..._ArgTypes>
2126 packaged_task<void(_ArgTypes...)>::reset()
2129 __throw_future_error(future_errc::no_state);
2130 __p_ = promise<result_type>();
2133 template <class _Rp, class... _ArgTypes>
2134 inline _LIBCPP_INLINE_VISIBILITY
2136 swap(packaged_task<_Rp(_ArgTypes...)>& __x, packaged_task<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
2141 template <class _Callable, class _Alloc>
2142 struct _LIBCPP_TEMPLATE_VIS uses_allocator<packaged_task<_Callable>, _Alloc>
2143 : public true_type {};
2145 template <class _Rp, class _Fp>
2146 _LIBCPP_INLINE_VISIBILITY future<_Rp>
2147 __make_deferred_assoc_state(_Fp&& __f)
2149 unique_ptr<__deferred_assoc_state<_Rp, _Fp>, __release_shared_count>
2150 __h(new __deferred_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f)));
2151 return future<_Rp>(__h.get());
2154 template <class _Rp, class _Fp>
2155 _LIBCPP_INLINE_VISIBILITY future<_Rp>
2156 __make_async_assoc_state(_Fp&& __f)
2158 unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count>
2159 __h(new __async_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f)));
2160 _VSTD::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach();
2161 return future<_Rp>(__h.get());
2164 #ifndef _LIBCPP_CXX03_LANG
2166 template <class _Fp, class... _Args>
2167 class _LIBCPP_HIDDEN __async_func
2169 tuple<_Fp, _Args...> __f_;
2172 typedef typename __invoke_of<_Fp, _Args...>::type _Rp;
2174 _LIBCPP_INLINE_VISIBILITY
2175 explicit __async_func(_Fp&& __f, _Args&&... __args)
2176 : __f_(_VSTD::move(__f), _VSTD::move(__args)...) {}
2178 _LIBCPP_INLINE_VISIBILITY
2179 __async_func(__async_func&& __f) : __f_(_VSTD::move(__f.__f_)) {}
2183 typedef typename __make_tuple_indices<1+sizeof...(_Args), 1>::type _Index;
2184 return __execute(_Index());
2187 template <size_t ..._Indices>
2189 __execute(__tuple_indices<_Indices...>)
2191 return _VSTD::__invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...);
2195 inline _LIBCPP_INLINE_VISIBILITY bool __does_policy_contain(launch __policy, launch __value )
2196 { return (int(__policy) & int(__value)) != 0; }
2198 template <class _Fp, class... _Args>
2199 _LIBCPP_NODISCARD_AFTER_CXX17
2200 future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type>
2201 async(launch __policy, _Fp&& __f, _Args&&... __args)
2203 typedef __async_func<typename decay<_Fp>::type, typename decay<_Args>::type...> _BF;
2204 typedef typename _BF::_Rp _Rp;
2206 #ifndef _LIBCPP_NO_EXCEPTIONS
2210 if (__does_policy_contain(__policy, launch::async))
2211 return _VSTD::__make_async_assoc_state<_Rp>(_BF(_LIBCPP_AUTO_CAST(_VSTD::forward<_Fp>(__f)),
2212 _LIBCPP_AUTO_CAST(_VSTD::forward<_Args>(__args))...));
2213 #ifndef _LIBCPP_NO_EXCEPTIONS
2215 catch ( ... ) { if (__policy == launch::async) throw ; }
2218 if (__does_policy_contain(__policy, launch::deferred))
2219 return _VSTD::__make_deferred_assoc_state<_Rp>(_BF(_LIBCPP_AUTO_CAST(_VSTD::forward<_Fp>(__f)),
2220 _LIBCPP_AUTO_CAST(_VSTD::forward<_Args>(__args))...));
2221 return future<_Rp>{};
2224 template <class _Fp, class... _Args>
2225 _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
2226 future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type>
2227 async(_Fp&& __f, _Args&&... __args)
2229 return _VSTD::async(launch::any, _VSTD::forward<_Fp>(__f),
2230 _VSTD::forward<_Args>(__args)...);
2237 template <class _Rp>
2238 class _LIBCPP_TEMPLATE_VIS shared_future
2240 __assoc_state<_Rp>* __state_;
2243 _LIBCPP_INLINE_VISIBILITY
2244 shared_future() _NOEXCEPT : __state_(nullptr) {}
2245 _LIBCPP_INLINE_VISIBILITY
2246 shared_future(const shared_future& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
2247 {if (__state_) __state_->__add_shared();}
2248 _LIBCPP_INLINE_VISIBILITY
2249 shared_future(future<_Rp>&& __f) _NOEXCEPT : __state_(__f.__state_)
2250 {__f.__state_ = nullptr;}
2251 _LIBCPP_INLINE_VISIBILITY
2252 shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
2253 {__rhs.__state_ = nullptr;}
2255 shared_future& operator=(const shared_future& __rhs) _NOEXCEPT;
2256 _LIBCPP_INLINE_VISIBILITY
2257 shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
2259 shared_future(_VSTD::move(__rhs)).swap(*this);
2263 // retrieving the value
2264 _LIBCPP_INLINE_VISIBILITY
2265 const _Rp& get() const {return __state_->copy();}
2267 _LIBCPP_INLINE_VISIBILITY
2268 void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
2270 // functions to check state
2271 _LIBCPP_INLINE_VISIBILITY
2272 bool valid() const _NOEXCEPT {return __state_ != nullptr;}
2274 _LIBCPP_INLINE_VISIBILITY
2275 void wait() const {__state_->wait();}
2276 template <class _Rep, class _Period>
2277 _LIBCPP_INLINE_VISIBILITY
2279 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
2280 {return __state_->wait_for(__rel_time);}
2281 template <class _Clock, class _Duration>
2282 _LIBCPP_INLINE_VISIBILITY
2284 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
2285 {return __state_->wait_until(__abs_time);}
2288 template <class _Rp>
2289 shared_future<_Rp>::~shared_future()
2292 __state_->__release_shared();
2295 template <class _Rp>
2297 shared_future<_Rp>::operator=(const shared_future& __rhs) _NOEXCEPT
2300 __rhs.__state_->__add_shared();
2302 __state_->__release_shared();
2303 __state_ = __rhs.__state_;
2307 template <class _Rp>
2308 class _LIBCPP_TEMPLATE_VIS shared_future<_Rp&>
2310 __assoc_state<_Rp&>* __state_;
2313 _LIBCPP_INLINE_VISIBILITY
2314 shared_future() _NOEXCEPT : __state_(nullptr) {}
2315 _LIBCPP_INLINE_VISIBILITY
2316 shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
2317 {if (__state_) __state_->__add_shared();}
2318 _LIBCPP_INLINE_VISIBILITY
2319 shared_future(future<_Rp&>&& __f) _NOEXCEPT : __state_(__f.__state_)
2320 {__f.__state_ = nullptr;}
2321 _LIBCPP_INLINE_VISIBILITY
2322 shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
2323 {__rhs.__state_ = nullptr;}
2325 shared_future& operator=(const shared_future& __rhs);
2326 _LIBCPP_INLINE_VISIBILITY
2327 shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
2329 shared_future(_VSTD::move(__rhs)).swap(*this);
2333 // retrieving the value
2334 _LIBCPP_INLINE_VISIBILITY
2335 _Rp& get() const {return __state_->copy();}
2337 _LIBCPP_INLINE_VISIBILITY
2338 void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
2340 // functions to check state
2341 _LIBCPP_INLINE_VISIBILITY
2342 bool valid() const _NOEXCEPT {return __state_ != nullptr;}
2344 _LIBCPP_INLINE_VISIBILITY
2345 void wait() const {__state_->wait();}
2346 template <class _Rep, class _Period>
2347 _LIBCPP_INLINE_VISIBILITY
2349 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
2350 {return __state_->wait_for(__rel_time);}
2351 template <class _Clock, class _Duration>
2352 _LIBCPP_INLINE_VISIBILITY
2354 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
2355 {return __state_->wait_until(__abs_time);}
2358 template <class _Rp>
2359 shared_future<_Rp&>::~shared_future()
2362 __state_->__release_shared();
2365 template <class _Rp>
2366 shared_future<_Rp&>&
2367 shared_future<_Rp&>::operator=(const shared_future& __rhs)
2370 __rhs.__state_->__add_shared();
2372 __state_->__release_shared();
2373 __state_ = __rhs.__state_;
2378 class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE shared_future<void>
2380 __assoc_sub_state* __state_;
2383 _LIBCPP_INLINE_VISIBILITY
2384 shared_future() _NOEXCEPT : __state_(nullptr) {}
2385 _LIBCPP_INLINE_VISIBILITY
2386 shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
2387 {if (__state_) __state_->__add_shared();}
2388 _LIBCPP_INLINE_VISIBILITY
2389 shared_future(future<void>&& __f) _NOEXCEPT : __state_(__f.__state_)
2390 {__f.__state_ = nullptr;}
2391 _LIBCPP_INLINE_VISIBILITY
2392 shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
2393 {__rhs.__state_ = nullptr;}
2395 shared_future& operator=(const shared_future& __rhs);
2396 _LIBCPP_INLINE_VISIBILITY
2397 shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
2399 shared_future(_VSTD::move(__rhs)).swap(*this);
2403 // retrieving the value
2404 _LIBCPP_INLINE_VISIBILITY
2405 void get() const {__state_->copy();}
2407 _LIBCPP_INLINE_VISIBILITY
2408 void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
2410 // functions to check state
2411 _LIBCPP_INLINE_VISIBILITY
2412 bool valid() const _NOEXCEPT {return __state_ != nullptr;}
2414 _LIBCPP_INLINE_VISIBILITY
2415 void wait() const {__state_->wait();}
2416 template <class _Rep, class _Period>
2417 _LIBCPP_INLINE_VISIBILITY
2419 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
2420 {return __state_->wait_for(__rel_time);}
2421 template <class _Clock, class _Duration>
2422 _LIBCPP_INLINE_VISIBILITY
2424 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
2425 {return __state_->wait_until(__abs_time);}
2428 template <class _Rp>
2429 inline _LIBCPP_INLINE_VISIBILITY
2431 swap(shared_future<_Rp>& __x, shared_future<_Rp>& __y) _NOEXCEPT
2436 template <class _Rp>
2439 future<_Rp>::share() _NOEXCEPT
2441 return shared_future<_Rp>(_VSTD::move(*this));
2444 template <class _Rp>
2447 future<_Rp&>::share() _NOEXCEPT
2449 return shared_future<_Rp&>(_VSTD::move(*this));
2454 future<void>::share() _NOEXCEPT
2456 return shared_future<void>(_VSTD::move(*this));
2459 _LIBCPP_END_NAMESPACE_STD
2461 #endif // !_LIBCPP_HAS_NO_THREADS
2463 #endif // _LIBCPP_FUTURE