2 //===--------------------------- future -----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_FUTURE
12 #define _LIBCPP_FUTURE
20 enum class future_errc
23 future_already_retrieved,
24 promise_already_satisfied,
32 any = async | deferred
35 enum class future_status
42 template <> struct is_error_code_enum<future_errc> : public true_type { };
43 error_code make_error_code(future_errc e);
44 error_condition make_error_condition(future_errc e);
46 const error_category& future_category();
52 future_error(error_code ec); // exposition only
54 const error_code& code() const throw();
55 const char* what() const throw();
63 template <class Allocator>
64 promise(allocator_arg_t, const Allocator& a);
65 promise(promise&& rhs);
66 promise(const promise& rhs) = delete;
70 promise& operator=(promise&& rhs);
71 promise& operator=(const promise& rhs) = delete;
72 void swap(promise& other);
74 // retrieving the result
75 future<R> get_future();
78 void set_value(const R& r);
79 void set_value(R&& r);
80 void set_exception(exception_ptr p);
82 // setting the result with deferred notification
83 void set_value_at_thread_exit(const R& r);
84 void set_value_at_thread_exit(R&& r);
85 void set_exception_at_thread_exit(exception_ptr p);
93 template <class Allocator>
94 promise(allocator_arg_t, const Allocator& a);
95 promise(promise&& rhs);
96 promise(const promise& rhs) = delete;
100 promise& operator=(promise&& rhs);
101 promise& operator=(const promise& rhs) = delete;
102 void swap(promise& other);
104 // retrieving the result
105 future<R&> get_future();
107 // setting the result
108 void set_value(R& r);
109 void set_exception(exception_ptr p);
111 // setting the result with deferred notification
112 void set_value_at_thread_exit(R&);
113 void set_exception_at_thread_exit(exception_ptr p);
121 template <class Allocator>
122 promise(allocator_arg_t, const Allocator& a);
123 promise(promise&& rhs);
124 promise(const promise& rhs) = delete;
128 promise& operator=(promise&& rhs);
129 promise& operator=(const promise& rhs) = delete;
130 void swap(promise& other);
132 // retrieving the result
133 future<void> get_future();
135 // setting the result
137 void set_exception(exception_ptr p);
139 // setting the result with deferred notification
140 void set_value_at_thread_exit();
141 void set_exception_at_thread_exit(exception_ptr p);
144 template <class R> void swap(promise<R>& x, promise<R>& y);
146 template <class R, class Alloc>
147 struct uses_allocator<promise<R>, Alloc> : public true_type {};
155 future(const future& rhs) = delete;
157 future& operator=(const future& rhs) = delete;
158 future& operator=(future&&);
159 shared_future<R> share() &&;
161 // retrieving the value
164 // functions to check state
168 template <class Rep, class Period>
170 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
171 template <class Clock, class Duration>
173 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
182 future(const future& rhs) = delete;
184 future& operator=(const future& rhs) = delete;
185 future& operator=(future&&);
186 shared_future<R&> share() &&;
188 // retrieving the value
191 // functions to check state
195 template <class Rep, class Period>
197 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
198 template <class Clock, class Duration>
200 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
209 future(const future& rhs) = delete;
211 future& operator=(const future& rhs) = delete;
212 future& operator=(future&&);
213 shared_future<void> share() &&;
215 // retrieving the value
218 // functions to check state
222 template <class Rep, class Period>
224 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
225 template <class Clock, class Duration>
227 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
235 shared_future(const shared_future& rhs);
236 shared_future(future<R>&&);
237 shared_future(shared_future&& rhs);
239 shared_future& operator=(const shared_future& rhs);
240 shared_future& operator=(shared_future&& rhs);
242 // retrieving the value
243 const R& get() const;
245 // functions to check state
249 template <class Rep, class Period>
251 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
252 template <class Clock, class Duration>
254 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
258 class shared_future<R&>
262 shared_future(const shared_future& rhs);
263 shared_future(future<R&>&&);
264 shared_future(shared_future&& rhs);
266 shared_future& operator=(const shared_future& rhs);
267 shared_future& operator=(shared_future&& rhs);
269 // retrieving the value
272 // functions to check state
276 template <class Rep, class Period>
278 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
279 template <class Clock, class Duration>
281 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
285 class shared_future<void>
289 shared_future(const shared_future& rhs);
290 shared_future(future<void>&&);
291 shared_future(shared_future&& rhs);
293 shared_future& operator=(const shared_future& rhs);
294 shared_future& operator=(shared_future&& rhs);
296 // retrieving the value
299 // functions to check state
303 template <class Rep, class Period>
305 wait_for(const chrono::duration<Rep, Period>& rel_time) const;
306 template <class Clock, class Duration>
308 wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
311 template <class F, class... Args>
312 future<typename result_of<F(Args...)>::type>
313 async(F&& f, Args&&... args);
315 template <class F, class... Args>
316 future<typename result_of<F(Args...)>::type>
317 async(launch policy, F&& f, Args&&... args);
319 template <class> class packaged_task; // undefined
321 template <class R, class... ArgTypes>
322 class packaged_task<R(ArgTypes...)>
325 typedef R result_type;
327 // construction and destruction
330 explicit packaged_task(F&& f);
331 template <class F, class Allocator>
332 explicit packaged_task(allocator_arg_t, const Allocator& a, F&& f);
336 packaged_task(packaged_task&) = delete;
337 packaged_task& operator=(packaged_task&) = delete;
340 packaged_task(packaged_task&& other);
341 packaged_task& operator=(packaged_task&& other);
342 void swap(packaged_task& other);
347 future<R> get_future();
350 void operator()(ArgTypes... );
351 void make_ready_at_thread_exit(ArgTypes...);
357 void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&);
359 template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
366 #include <system_error>
373 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
374 #pragma GCC system_header
377 _LIBCPP_BEGIN_NAMESPACE_STD
379 //enum class future_errc
380 _LIBCPP_DECLARE_STRONG_ENUM(future_errc)
383 future_already_retrieved,
384 promise_already_satisfied,
387 _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc)
390 struct _LIBCPP_VISIBLE is_error_code_enum<future_errc> : public true_type {};
392 #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
394 struct _LIBCPP_VISIBLE is_error_code_enum<future_errc::_> : public true_type { };
398 _LIBCPP_DECLARE_STRONG_ENUM(launch)
402 any = async | deferred
404 _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch)
406 //enum class future_status
407 _LIBCPP_DECLARE_STRONG_ENUM(future_status)
413 _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_status)
416 const error_category& future_category();
418 inline _LIBCPP_INLINE_VISIBILITY
420 make_error_code(future_errc __e)
422 return error_code(static_cast<int>(__e), future_category());
425 inline _LIBCPP_INLINE_VISIBILITY
427 make_error_condition(future_errc __e)
429 return error_condition(static_cast<int>(__e), future_category());
432 class _LIBCPP_EXCEPTION_ABI future_error
437 future_error(error_code __ec);
439 _LIBCPP_INLINE_VISIBILITY
440 const error_code& code() const throw() {return __ec_;}
442 virtual ~future_error() _NOEXCEPT;
445 class __assoc_sub_state
446 : public __shared_count
449 exception_ptr __exception_;
450 mutable mutex __mut_;
451 mutable condition_variable __cv_;
454 virtual void __on_zero_shared() _NOEXCEPT;
455 void __sub_wait(unique_lock<mutex>& __lk);
460 __future_attached = 2,
465 _LIBCPP_INLINE_VISIBILITY
466 __assoc_sub_state() : __state_(0) {}
468 _LIBCPP_INLINE_VISIBILITY
469 bool __has_value() const
470 {return (__state_ & __constructed) || (__exception_ != nullptr);}
472 _LIBCPP_INLINE_VISIBILITY
473 void __set_future_attached() {__state_ |= __future_attached;}
474 _LIBCPP_INLINE_VISIBILITY
475 bool __has_future_attached() const {return __state_ & __future_attached;}
477 _LIBCPP_INLINE_VISIBILITY
478 void __set_deferred() {__state_ |= deferred;}
481 _LIBCPP_INLINE_VISIBILITY
482 bool __is_ready() const {return __state_ & ready;}
485 void set_value_at_thread_exit();
487 void set_exception(exception_ptr __p);
488 void set_exception_at_thread_exit(exception_ptr __p);
493 template <class _Rep, class _Period>
495 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const;
496 template <class _Clock, class _Duration>
498 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const;
500 virtual void __execute();
503 template <class _Clock, class _Duration>
505 __assoc_sub_state::wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
507 unique_lock<mutex> __lk(__mut_);
508 if (__state_ & deferred)
509 return future_status::deferred;
510 while (!(__state_ & ready) && _Clock::now() < __abs_time)
511 __cv_.wait_until(__lk, __abs_time);
512 if (__state_ & ready)
513 return future_status::ready;
514 return future_status::timeout;
517 template <class _Rep, class _Period>
518 inline _LIBCPP_INLINE_VISIBILITY
520 __assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
522 return wait_until(chrono::steady_clock::now() + __rel_time);
527 : public __assoc_sub_state
529 typedef __assoc_sub_state base;
530 typedef typename aligned_storage<sizeof(_Rp), alignment_of<_Rp>::value>::type _Up;
534 virtual void __on_zero_shared() _NOEXCEPT;
537 template <class _Arg>
538 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
539 void set_value(_Arg&& __arg);
541 void set_value(_Arg& __arg);
544 template <class _Arg>
545 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
546 void set_value_at_thread_exit(_Arg&& __arg);
548 void set_value_at_thread_exit(_Arg& __arg);
552 typename add_lvalue_reference<_Rp>::type copy();
557 __assoc_state<_Rp>::__on_zero_shared() _NOEXCEPT
559 if (this->__state_ & base::__constructed)
560 reinterpret_cast<_Rp*>(&__value_)->~_Rp();
565 template <class _Arg>
567 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
568 __assoc_state<_Rp>::set_value(_Arg&& __arg)
570 __assoc_state<_Rp>::set_value(_Arg& __arg)
573 unique_lock<mutex> __lk(this->__mut_);
574 #ifndef _LIBCPP_NO_EXCEPTIONS
575 if (this->__has_value())
576 throw future_error(make_error_code(future_errc::promise_already_satisfied));
578 ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
579 this->__state_ |= base::__constructed | base::ready;
585 template <class _Arg>
587 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
588 __assoc_state<_Rp>::set_value_at_thread_exit(_Arg&& __arg)
590 __assoc_state<_Rp>::set_value_at_thread_exit(_Arg& __arg)
593 unique_lock<mutex> __lk(this->__mut_);
594 #ifndef _LIBCPP_NO_EXCEPTIONS
595 if (this->__has_value())
596 throw future_error(make_error_code(future_errc::promise_already_satisfied));
598 ::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
599 this->__state_ |= base::__constructed;
600 __thread_local_data()->__make_ready_at_thread_exit(this);
606 __assoc_state<_Rp>::move()
608 unique_lock<mutex> __lk(this->__mut_);
609 this->__sub_wait(__lk);
610 if (this->__exception_ != nullptr)
611 rethrow_exception(this->__exception_);
612 return _VSTD::move(*reinterpret_cast<_Rp*>(&__value_));
616 typename add_lvalue_reference<_Rp>::type
617 __assoc_state<_Rp>::copy()
619 unique_lock<mutex> __lk(this->__mut_);
620 this->__sub_wait(__lk);
621 if (this->__exception_ != nullptr)
622 rethrow_exception(this->__exception_);
623 return *reinterpret_cast<_Rp*>(&__value_);
627 class __assoc_state<_Rp&>
628 : public __assoc_sub_state
630 typedef __assoc_sub_state base;
635 virtual void __on_zero_shared() _NOEXCEPT;
638 void set_value(_Rp& __arg);
639 void set_value_at_thread_exit(_Rp& __arg);
646 __assoc_state<_Rp&>::__on_zero_shared() _NOEXCEPT
653 __assoc_state<_Rp&>::set_value(_Rp& __arg)
655 unique_lock<mutex> __lk(this->__mut_);
656 #ifndef _LIBCPP_NO_EXCEPTIONS
657 if (this->__has_value())
658 throw future_error(make_error_code(future_errc::promise_already_satisfied));
661 this->__state_ |= base::__constructed | base::ready;
668 __assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg)
670 unique_lock<mutex> __lk(this->__mut_);
671 #ifndef _LIBCPP_NO_EXCEPTIONS
672 if (this->__has_value())
673 throw future_error(make_error_code(future_errc::promise_already_satisfied));
676 this->__state_ |= base::__constructed;
677 __thread_local_data()->__make_ready_at_thread_exit(this);
683 __assoc_state<_Rp&>::copy()
685 unique_lock<mutex> __lk(this->__mut_);
686 this->__sub_wait(__lk);
687 if (this->__exception_ != nullptr)
688 rethrow_exception(this->__exception_);
692 template <class _Rp, class _Alloc>
693 class __assoc_state_alloc
694 : public __assoc_state<_Rp>
696 typedef __assoc_state<_Rp> base;
699 virtual void __on_zero_shared() _NOEXCEPT;
701 _LIBCPP_INLINE_VISIBILITY
702 explicit __assoc_state_alloc(const _Alloc& __a)
706 template <class _Rp, class _Alloc>
708 __assoc_state_alloc<_Rp, _Alloc>::__on_zero_shared() _NOEXCEPT
710 if (this->__state_ & base::__constructed)
711 reinterpret_cast<_Rp*>(&this->__value_)->~_Rp();
712 typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_);
713 this->~__assoc_state_alloc();
714 __a.deallocate(this, 1);
717 template <class _Rp, class _Alloc>
718 class __assoc_state_alloc<_Rp&, _Alloc>
719 : public __assoc_state<_Rp&>
721 typedef __assoc_state<_Rp&> base;
724 virtual void __on_zero_shared() _NOEXCEPT;
726 _LIBCPP_INLINE_VISIBILITY
727 explicit __assoc_state_alloc(const _Alloc& __a)
731 template <class _Rp, class _Alloc>
733 __assoc_state_alloc<_Rp&, _Alloc>::__on_zero_shared() _NOEXCEPT
735 typename _Alloc::template rebind<__assoc_state_alloc>::other __a(__alloc_);
736 this->~__assoc_state_alloc();
737 __a.deallocate(this, 1);
740 template <class _Alloc>
741 class __assoc_sub_state_alloc
742 : public __assoc_sub_state
744 typedef __assoc_sub_state base;
747 virtual void __on_zero_shared() _NOEXCEPT;
749 _LIBCPP_INLINE_VISIBILITY
750 explicit __assoc_sub_state_alloc(const _Alloc& __a)
754 template <class _Alloc>
756 __assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT
759 typename _Alloc::template rebind<__assoc_sub_state_alloc>::other __a(__alloc_);
760 this->~__assoc_sub_state_alloc();
761 __a.deallocate(this, 1);
764 template <class _Rp, class _Fp>
765 class __deferred_assoc_state
766 : public __assoc_state<_Rp>
768 typedef __assoc_state<_Rp> base;
773 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
774 explicit __deferred_assoc_state(_Fp&& __f);
777 virtual void __execute();
780 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
782 template <class _Rp, class _Fp>
783 inline _LIBCPP_INLINE_VISIBILITY
784 __deferred_assoc_state<_Rp, _Fp>::__deferred_assoc_state(_Fp&& __f)
785 : __func_(_VSTD::forward<_Fp>(__f))
787 this->__set_deferred();
790 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
792 template <class _Rp, class _Fp>
794 __deferred_assoc_state<_Rp, _Fp>::__execute()
796 #ifndef _LIBCPP_NO_EXCEPTIONS
799 #endif // _LIBCPP_NO_EXCEPTIONS
800 this->set_value(__func_());
801 #ifndef _LIBCPP_NO_EXCEPTIONS
805 this->set_exception(current_exception());
807 #endif // _LIBCPP_NO_EXCEPTIONS
811 class __deferred_assoc_state<void, _Fp>
812 : public __assoc_sub_state
814 typedef __assoc_sub_state base;
819 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
820 explicit __deferred_assoc_state(_Fp&& __f);
823 virtual void __execute();
826 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
829 inline _LIBCPP_INLINE_VISIBILITY
830 __deferred_assoc_state<void, _Fp>::__deferred_assoc_state(_Fp&& __f)
831 : __func_(_VSTD::forward<_Fp>(__f))
833 this->__set_deferred();
836 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
840 __deferred_assoc_state<void, _Fp>::__execute()
842 #ifndef _LIBCPP_NO_EXCEPTIONS
845 #endif // _LIBCPP_NO_EXCEPTIONS
848 #ifndef _LIBCPP_NO_EXCEPTIONS
852 this->set_exception(current_exception());
854 #endif // _LIBCPP_NO_EXCEPTIONS
857 template <class _Rp, class _Fp>
858 class __async_assoc_state
859 : public __assoc_state<_Rp>
861 typedef __assoc_state<_Rp> base;
865 virtual void __on_zero_shared() _NOEXCEPT;
867 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
868 explicit __async_assoc_state(_Fp&& __f);
871 virtual void __execute();
874 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
876 template <class _Rp, class _Fp>
877 inline _LIBCPP_INLINE_VISIBILITY
878 __async_assoc_state<_Rp, _Fp>::__async_assoc_state(_Fp&& __f)
879 : __func_(_VSTD::forward<_Fp>(__f))
883 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
885 template <class _Rp, class _Fp>
887 __async_assoc_state<_Rp, _Fp>::__execute()
889 #ifndef _LIBCPP_NO_EXCEPTIONS
892 #endif // _LIBCPP_NO_EXCEPTIONS
893 this->set_value(__func_());
894 #ifndef _LIBCPP_NO_EXCEPTIONS
898 this->set_exception(current_exception());
900 #endif // _LIBCPP_NO_EXCEPTIONS
903 template <class _Rp, class _Fp>
905 __async_assoc_state<_Rp, _Fp>::__on_zero_shared() _NOEXCEPT
908 base::__on_zero_shared();
912 class __async_assoc_state<void, _Fp>
913 : public __assoc_sub_state
915 typedef __assoc_sub_state base;
919 virtual void __on_zero_shared() _NOEXCEPT;
921 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
922 explicit __async_assoc_state(_Fp&& __f);
925 virtual void __execute();
928 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
931 inline _LIBCPP_INLINE_VISIBILITY
932 __async_assoc_state<void, _Fp>::__async_assoc_state(_Fp&& __f)
933 : __func_(_VSTD::forward<_Fp>(__f))
937 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
941 __async_assoc_state<void, _Fp>::__execute()
943 #ifndef _LIBCPP_NO_EXCEPTIONS
946 #endif // _LIBCPP_NO_EXCEPTIONS
949 #ifndef _LIBCPP_NO_EXCEPTIONS
953 this->set_exception(current_exception());
955 #endif // _LIBCPP_NO_EXCEPTIONS
960 __async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT
963 base::__on_zero_shared();
966 template <class _Rp> class promise;
967 template <class _Rp> class shared_future;
971 template <class _Rp> class future;
973 template <class _Rp, class _Fp>
975 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
976 __make_deferred_assoc_state(_Fp&& __f);
978 __make_deferred_assoc_state(_Fp __f);
981 template <class _Rp, class _Fp>
983 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
984 __make_async_assoc_state(_Fp&& __f);
986 __make_async_assoc_state(_Fp __f);
990 class _LIBCPP_VISIBLE future
992 __assoc_state<_Rp>* __state_;
994 explicit future(__assoc_state<_Rp>* __state);
996 template <class> friend class promise;
997 template <class> friend class shared_future;
999 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1000 template <class _R1, class _Fp>
1001 friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
1002 template <class _R1, class _Fp>
1003 friend future<_R1> __make_async_assoc_state(_Fp&& __f);
1005 template <class _R1, class _Fp>
1006 friend future<_R1> __make_deferred_assoc_state(_Fp __f);
1007 template <class _R1, class _Fp>
1008 friend future<_R1> __make_async_assoc_state(_Fp __f);
1012 _LIBCPP_INLINE_VISIBILITY
1013 future() : __state_(nullptr) {}
1014 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1015 _LIBCPP_INLINE_VISIBILITY
1016 future(future&& __rhs)
1017 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1018 future(const future&) = delete;
1019 future& operator=(const future&) = delete;
1020 _LIBCPP_INLINE_VISIBILITY
1021 future& operator=(future&& __rhs)
1023 future(std::move(__rhs)).swap(*this);
1026 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1028 future(const future&);
1029 future& operator=(const future&);
1031 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1033 shared_future<_Rp> share();
1035 // retrieving the value
1038 _LIBCPP_INLINE_VISIBILITY
1039 void swap(future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
1041 // functions to check state
1042 _LIBCPP_INLINE_VISIBILITY
1043 bool valid() const {return __state_ != nullptr;}
1045 _LIBCPP_INLINE_VISIBILITY
1046 void wait() const {__state_->wait();}
1047 template <class _Rep, class _Period>
1048 _LIBCPP_INLINE_VISIBILITY
1050 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
1051 {return __state_->wait_for(__rel_time);}
1052 template <class _Clock, class _Duration>
1053 _LIBCPP_INLINE_VISIBILITY
1055 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
1056 {return __state_->wait_until(__abs_time);}
1059 template <class _Rp>
1060 future<_Rp>::future(__assoc_state<_Rp>* __state)
1063 #ifndef _LIBCPP_NO_EXCEPTIONS
1064 if (__state_->__has_future_attached())
1065 throw future_error(make_error_code(future_errc::future_already_retrieved));
1067 __state_->__add_shared();
1068 __state_->__set_future_attached();
1071 struct __release_shared_count
1073 void operator()(__shared_count* p) {p->__release_shared();}
1076 template <class _Rp>
1077 future<_Rp>::~future()
1080 __state_->__release_shared();
1083 template <class _Rp>
1087 unique_ptr<__shared_count, __release_shared_count> __(__state_);
1088 __assoc_state<_Rp>* __s = __state_;
1093 template <class _Rp>
1094 class _LIBCPP_VISIBLE future<_Rp&>
1096 __assoc_state<_Rp&>* __state_;
1098 explicit future(__assoc_state<_Rp&>* __state);
1100 template <class> friend class promise;
1101 template <class> friend class shared_future;
1103 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1104 template <class _R1, class _Fp>
1105 friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
1106 template <class _R1, class _Fp>
1107 friend future<_R1> __make_async_assoc_state(_Fp&& __f);
1109 template <class _R1, class _Fp>
1110 friend future<_R1> __make_deferred_assoc_state(_Fp __f);
1111 template <class _R1, class _Fp>
1112 friend future<_R1> __make_async_assoc_state(_Fp __f);
1116 _LIBCPP_INLINE_VISIBILITY
1117 future() : __state_(nullptr) {}
1118 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1119 _LIBCPP_INLINE_VISIBILITY
1120 future(future&& __rhs)
1121 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1122 future(const future&) = delete;
1123 future& operator=(const future&) = delete;
1124 _LIBCPP_INLINE_VISIBILITY
1125 future& operator=(future&& __rhs)
1127 future(std::move(__rhs)).swap(*this);
1130 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1132 future(const future&);
1133 future& operator=(const future&);
1135 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1137 shared_future<_Rp&> share();
1139 // retrieving the value
1142 _LIBCPP_INLINE_VISIBILITY
1143 void swap(future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
1145 // functions to check state
1146 _LIBCPP_INLINE_VISIBILITY
1147 bool valid() const {return __state_ != nullptr;}
1149 _LIBCPP_INLINE_VISIBILITY
1150 void wait() const {__state_->wait();}
1151 template <class _Rep, class _Period>
1152 _LIBCPP_INLINE_VISIBILITY
1154 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
1155 {return __state_->wait_for(__rel_time);}
1156 template <class _Clock, class _Duration>
1157 _LIBCPP_INLINE_VISIBILITY
1159 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
1160 {return __state_->wait_until(__abs_time);}
1163 template <class _Rp>
1164 future<_Rp&>::future(__assoc_state<_Rp&>* __state)
1167 #ifndef _LIBCPP_NO_EXCEPTIONS
1168 if (__state_->__has_future_attached())
1169 throw future_error(make_error_code(future_errc::future_already_retrieved));
1171 __state_->__add_shared();
1172 __state_->__set_future_attached();
1175 template <class _Rp>
1176 future<_Rp&>::~future()
1179 __state_->__release_shared();
1182 template <class _Rp>
1186 unique_ptr<__shared_count, __release_shared_count> __(__state_);
1187 __assoc_state<_Rp&>* __s = __state_;
1193 class _LIBCPP_VISIBLE future<void>
1195 __assoc_sub_state* __state_;
1197 explicit future(__assoc_sub_state* __state);
1199 template <class> friend class promise;
1200 template <class> friend class shared_future;
1202 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1203 template <class _R1, class _Fp>
1204 friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
1205 template <class _R1, class _Fp>
1206 friend future<_R1> __make_async_assoc_state(_Fp&& __f);
1208 template <class _R1, class _Fp>
1209 friend future<_R1> __make_deferred_assoc_state(_Fp __f);
1210 template <class _R1, class _Fp>
1211 friend future<_R1> __make_async_assoc_state(_Fp __f);
1215 _LIBCPP_INLINE_VISIBILITY
1216 future() : __state_(nullptr) {}
1217 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1218 _LIBCPP_INLINE_VISIBILITY
1219 future(future&& __rhs)
1220 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1221 future(const future&) = delete;
1222 future& operator=(const future&) = delete;
1223 _LIBCPP_INLINE_VISIBILITY
1224 future& operator=(future&& __rhs)
1226 future(std::move(__rhs)).swap(*this);
1229 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1231 future(const future&);
1232 future& operator=(const future&);
1234 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1236 shared_future<void> share();
1238 // retrieving the value
1241 _LIBCPP_INLINE_VISIBILITY
1242 void swap(future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
1244 // functions to check state
1245 _LIBCPP_INLINE_VISIBILITY
1246 bool valid() const {return __state_ != nullptr;}
1248 _LIBCPP_INLINE_VISIBILITY
1249 void wait() const {__state_->wait();}
1250 template <class _Rep, class _Period>
1251 _LIBCPP_INLINE_VISIBILITY
1253 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
1254 {return __state_->wait_for(__rel_time);}
1255 template <class _Clock, class _Duration>
1256 _LIBCPP_INLINE_VISIBILITY
1258 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
1259 {return __state_->wait_until(__abs_time);}
1262 template <class _Rp>
1263 inline _LIBCPP_INLINE_VISIBILITY
1265 swap(future<_Rp>& __x, future<_Rp>& __y)
1272 template <class _Callable> class packaged_task;
1274 template <class _Rp>
1275 class _LIBCPP_VISIBLE promise
1277 __assoc_state<_Rp>* __state_;
1279 _LIBCPP_INLINE_VISIBILITY
1280 explicit promise(nullptr_t) : __state_(nullptr) {}
1282 template <class> friend class packaged_task;
1285 template <class _Alloc>
1286 promise(allocator_arg_t, const _Alloc& __a);
1287 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1288 _LIBCPP_INLINE_VISIBILITY
1289 promise(promise&& __rhs)
1290 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1291 promise(const promise& __rhs) = delete;
1292 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1294 promise(const promise& __rhs);
1296 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1300 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1301 _LIBCPP_INLINE_VISIBILITY
1302 promise& operator=(promise&& __rhs)
1304 promise(std::move(__rhs)).swap(*this);
1307 promise& operator=(const promise& __rhs) = delete;
1308 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1310 promise& operator=(const promise& __rhs);
1312 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1313 _LIBCPP_INLINE_VISIBILITY
1314 void swap(promise& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
1316 // retrieving the result
1317 future<_Rp> get_future();
1319 // setting the result
1320 void set_value(const _Rp& __r);
1321 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1322 void set_value(_Rp&& __r);
1324 void set_exception(exception_ptr __p);
1326 // setting the result with deferred notification
1327 void set_value_at_thread_exit(const _Rp& __r);
1328 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1329 void set_value_at_thread_exit(_Rp&& __r);
1331 void set_exception_at_thread_exit(exception_ptr __p);
1334 template <class _Rp>
1335 promise<_Rp>::promise()
1336 : __state_(new __assoc_state<_Rp>)
1340 template <class _Rp>
1341 template <class _Alloc>
1342 promise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0)
1344 typedef typename _Alloc::template rebind<__assoc_state_alloc<_Rp, _Alloc> >::other _A2;
1345 typedef __allocator_destructor<_A2> _D2;
1347 unique_ptr<__assoc_state_alloc<_Rp, _Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1));
1348 ::new(__hold.get()) __assoc_state_alloc<_Rp, _Alloc>(__a0);
1349 __state_ = __hold.release();
1352 template <class _Rp>
1353 promise<_Rp>::~promise()
1357 if (!__state_->__has_value() && __state_->use_count() > 1)
1358 __state_->set_exception(make_exception_ptr(
1359 future_error(make_error_code(future_errc::broken_promise))
1361 __state_->__release_shared();
1365 template <class _Rp>
1367 promise<_Rp>::get_future()
1369 #ifndef _LIBCPP_NO_EXCEPTIONS
1370 if (__state_ == nullptr)
1371 throw future_error(make_error_code(future_errc::no_state));
1373 return future<_Rp>(__state_);
1376 template <class _Rp>
1378 promise<_Rp>::set_value(const _Rp& __r)
1380 #ifndef _LIBCPP_NO_EXCEPTIONS
1381 if (__state_ == nullptr)
1382 throw future_error(make_error_code(future_errc::no_state));
1384 __state_->set_value(__r);
1387 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1389 template <class _Rp>
1391 promise<_Rp>::set_value(_Rp&& __r)
1393 #ifndef _LIBCPP_NO_EXCEPTIONS
1394 if (__state_ == nullptr)
1395 throw future_error(make_error_code(future_errc::no_state));
1397 __state_->set_value(_VSTD::move(__r));
1400 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1402 template <class _Rp>
1404 promise<_Rp>::set_exception(exception_ptr __p)
1406 #ifndef _LIBCPP_NO_EXCEPTIONS
1407 if (__state_ == nullptr)
1408 throw future_error(make_error_code(future_errc::no_state));
1410 __state_->set_exception(__p);
1413 template <class _Rp>
1415 promise<_Rp>::set_value_at_thread_exit(const _Rp& __r)
1417 #ifndef _LIBCPP_NO_EXCEPTIONS
1418 if (__state_ == nullptr)
1419 throw future_error(make_error_code(future_errc::no_state));
1421 __state_->set_value_at_thread_exit(__r);
1424 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1426 template <class _Rp>
1428 promise<_Rp>::set_value_at_thread_exit(_Rp&& __r)
1430 #ifndef _LIBCPP_NO_EXCEPTIONS
1431 if (__state_ == nullptr)
1432 throw future_error(make_error_code(future_errc::no_state));
1434 __state_->set_value_at_thread_exit(_VSTD::move(__r));
1437 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1439 template <class _Rp>
1441 promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p)
1443 #ifndef _LIBCPP_NO_EXCEPTIONS
1444 if (__state_ == nullptr)
1445 throw future_error(make_error_code(future_errc::no_state));
1447 __state_->set_exception_at_thread_exit(__p);
1452 template <class _Rp>
1453 class _LIBCPP_VISIBLE promise<_Rp&>
1455 __assoc_state<_Rp&>* __state_;
1457 _LIBCPP_INLINE_VISIBILITY
1458 explicit promise(nullptr_t) : __state_(nullptr) {}
1460 template <class> friend class packaged_task;
1464 template <class _Allocator>
1465 promise(allocator_arg_t, const _Allocator& __a);
1466 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1467 _LIBCPP_INLINE_VISIBILITY
1468 promise(promise&& __rhs)
1469 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1470 promise(const promise& __rhs) = delete;
1471 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1473 promise(const promise& __rhs);
1475 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1479 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1480 _LIBCPP_INLINE_VISIBILITY
1481 promise& operator=(promise&& __rhs)
1483 promise(std::move(__rhs)).swap(*this);
1486 promise& operator=(const promise& __rhs) = delete;
1487 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1489 promise& operator=(const promise& __rhs);
1491 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1492 _LIBCPP_INLINE_VISIBILITY
1493 void swap(promise& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
1495 // retrieving the result
1496 future<_Rp&> get_future();
1498 // setting the result
1499 void set_value(_Rp& __r);
1500 void set_exception(exception_ptr __p);
1502 // setting the result with deferred notification
1503 void set_value_at_thread_exit(_Rp&);
1504 void set_exception_at_thread_exit(exception_ptr __p);
1507 template <class _Rp>
1508 promise<_Rp&>::promise()
1509 : __state_(new __assoc_state<_Rp&>)
1513 template <class _Rp>
1514 template <class _Alloc>
1515 promise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0)
1517 typedef typename _Alloc::template rebind<__assoc_state_alloc<_Rp&, _Alloc> >::other _A2;
1518 typedef __allocator_destructor<_A2> _D2;
1520 unique_ptr<__assoc_state_alloc<_Rp&, _Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1));
1521 ::new(__hold.get()) __assoc_state_alloc<_Rp&, _Alloc>(__a0);
1522 __state_ = __hold.release();
1525 template <class _Rp>
1526 promise<_Rp&>::~promise()
1530 if (!__state_->__has_value() && __state_->use_count() > 1)
1531 __state_->set_exception(make_exception_ptr(
1532 future_error(make_error_code(future_errc::broken_promise))
1534 __state_->__release_shared();
1538 template <class _Rp>
1540 promise<_Rp&>::get_future()
1542 #ifndef _LIBCPP_NO_EXCEPTIONS
1543 if (__state_ == nullptr)
1544 throw future_error(make_error_code(future_errc::no_state));
1546 return future<_Rp&>(__state_);
1549 template <class _Rp>
1551 promise<_Rp&>::set_value(_Rp& __r)
1553 #ifndef _LIBCPP_NO_EXCEPTIONS
1554 if (__state_ == nullptr)
1555 throw future_error(make_error_code(future_errc::no_state));
1557 __state_->set_value(__r);
1560 template <class _Rp>
1562 promise<_Rp&>::set_exception(exception_ptr __p)
1564 #ifndef _LIBCPP_NO_EXCEPTIONS
1565 if (__state_ == nullptr)
1566 throw future_error(make_error_code(future_errc::no_state));
1568 __state_->set_exception(__p);
1571 template <class _Rp>
1573 promise<_Rp&>::set_value_at_thread_exit(_Rp& __r)
1575 #ifndef _LIBCPP_NO_EXCEPTIONS
1576 if (__state_ == nullptr)
1577 throw future_error(make_error_code(future_errc::no_state));
1579 __state_->set_value_at_thread_exit(__r);
1582 template <class _Rp>
1584 promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p)
1586 #ifndef _LIBCPP_NO_EXCEPTIONS
1587 if (__state_ == nullptr)
1588 throw future_error(make_error_code(future_errc::no_state));
1590 __state_->set_exception_at_thread_exit(__p);
1596 class _LIBCPP_VISIBLE promise<void>
1598 __assoc_sub_state* __state_;
1600 _LIBCPP_INLINE_VISIBILITY
1601 explicit promise(nullptr_t) : __state_(nullptr) {}
1603 template <class> friend class packaged_task;
1607 template <class _Allocator>
1608 promise(allocator_arg_t, const _Allocator& __a);
1609 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1610 _LIBCPP_INLINE_VISIBILITY
1611 promise(promise&& __rhs)
1612 : __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
1613 promise(const promise& __rhs) = delete;
1614 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1616 promise(const promise& __rhs);
1618 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1622 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1623 _LIBCPP_INLINE_VISIBILITY
1624 promise& operator=(promise&& __rhs)
1626 promise(std::move(__rhs)).swap(*this);
1629 promise& operator=(const promise& __rhs) = delete;
1630 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1632 promise& operator=(const promise& __rhs);
1634 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1635 _LIBCPP_INLINE_VISIBILITY
1636 void swap(promise& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
1638 // retrieving the result
1639 future<void> get_future();
1641 // setting the result
1643 void set_exception(exception_ptr __p);
1645 // setting the result with deferred notification
1646 void set_value_at_thread_exit();
1647 void set_exception_at_thread_exit(exception_ptr __p);
1650 template <class _Alloc>
1651 promise<void>::promise(allocator_arg_t, const _Alloc& __a0)
1653 typedef typename _Alloc::template rebind<__assoc_sub_state_alloc<_Alloc> >::other _A2;
1654 typedef __allocator_destructor<_A2> _D2;
1656 unique_ptr<__assoc_sub_state_alloc<_Alloc>, _D2> __hold(__a.allocate(1), _D2(__a, 1));
1657 ::new(__hold.get()) __assoc_sub_state_alloc<_Alloc>(__a0);
1658 __state_ = __hold.release();
1661 template <class _Rp>
1662 inline _LIBCPP_INLINE_VISIBILITY
1664 swap(promise<_Rp>& __x, promise<_Rp>& __y)
1669 template <class _Rp, class _Alloc>
1670 struct _LIBCPP_VISIBLE uses_allocator<promise<_Rp>, _Alloc>
1671 : public true_type {};
1673 #ifndef _LIBCPP_HAS_NO_VARIADICS
1677 template<class _Fp> class __packaged_task_base;
1679 template<class _Rp, class ..._ArgTypes>
1680 class __packaged_task_base<_Rp(_ArgTypes...)>
1682 __packaged_task_base(const __packaged_task_base&);
1683 __packaged_task_base& operator=(const __packaged_task_base&);
1685 _LIBCPP_INLINE_VISIBILITY
1686 __packaged_task_base() {}
1687 _LIBCPP_INLINE_VISIBILITY
1688 virtual ~__packaged_task_base() {}
1689 virtual void __move_to(__packaged_task_base*) = 0;
1690 virtual void destroy() = 0;
1691 virtual void destroy_deallocate() = 0;
1692 virtual _Rp operator()(_ArgTypes&& ...) = 0;
1695 template<class _FD, class _Alloc, class _FB> class __packaged_task_func;
1697 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1698 class __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1699 : public __packaged_task_base<_Rp(_ArgTypes...)>
1701 __compressed_pair<_Fp, _Alloc> __f_;
1703 _LIBCPP_INLINE_VISIBILITY
1704 explicit __packaged_task_func(const _Fp& __f) : __f_(__f) {}
1705 _LIBCPP_INLINE_VISIBILITY
1706 explicit __packaged_task_func(_Fp&& __f) : __f_(_VSTD::move(__f)) {}
1707 _LIBCPP_INLINE_VISIBILITY
1708 __packaged_task_func(const _Fp& __f, const _Alloc& __a)
1710 _LIBCPP_INLINE_VISIBILITY
1711 __packaged_task_func(_Fp&& __f, const _Alloc& __a)
1712 : __f_(_VSTD::move(__f), __a) {}
1713 virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*);
1714 virtual void destroy();
1715 virtual void destroy_deallocate();
1716 virtual _Rp operator()(_ArgTypes&& ... __args);
1719 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1721 __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to(
1722 __packaged_task_base<_Rp(_ArgTypes...)>* __p)
1724 ::new (__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second()));
1727 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1729 __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy()
1731 __f_.~__compressed_pair<_Fp, _Alloc>();
1734 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1736 __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate()
1738 typedef typename _Alloc::template rebind<__packaged_task_func>::other _Ap;
1739 _Ap __a(__f_.second());
1740 __f_.~__compressed_pair<_Fp, _Alloc>();
1741 __a.deallocate(this, 1);
1744 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1746 __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1748 return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
1751 template <class _Callable> class __packaged_task_function;
1753 template<class _Rp, class ..._ArgTypes>
1754 class __packaged_task_function<_Rp(_ArgTypes...)>
1756 typedef __packaged_task_base<_Rp(_ArgTypes...)> __base;
1757 aligned_storage<3*sizeof(void*)>::type __buf_;
1761 typedef _Rp result_type;
1763 // construct/copy/destroy:
1764 _LIBCPP_INLINE_VISIBILITY
1765 __packaged_task_function() : __f_(nullptr) {}
1767 __packaged_task_function(_Fp&& __f);
1768 template<class _Fp, class _Alloc>
1769 __packaged_task_function(allocator_arg_t, const _Alloc& __a, _Fp&& __f);
1771 __packaged_task_function(__packaged_task_function&&);
1772 __packaged_task_function& operator=(__packaged_task_function&&);
1774 __packaged_task_function(const __packaged_task_function&) = delete;
1775 __packaged_task_function& operator=(const __packaged_task_function&) = delete;
1777 ~__packaged_task_function();
1779 void swap(__packaged_task_function&);
1781 _Rp operator()(_ArgTypes...) const;
1784 template<class _Rp, class ..._ArgTypes>
1785 __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f)
1787 if (__f.__f_ == nullptr)
1789 else if (__f.__f_ == (__base*)&__f.__buf_)
1791 __f_ = (__base*)&__buf_;
1792 __f.__f_->__move_to(__f_);
1801 template<class _Rp, class ..._ArgTypes>
1802 template <class _Fp>
1803 __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f)
1806 typedef typename remove_reference<_Fp>::type _FR;
1807 typedef __packaged_task_func<_FR, allocator<_FR>, _Rp(_ArgTypes...)> _FF;
1808 if (sizeof(_FF) <= sizeof(__buf_))
1810 __f_ = (__base*)&__buf_;
1811 ::new (__f_) _FF(_VSTD::forward<_Fp>(__f));
1815 typedef allocator<_FF> _Ap;
1817 typedef __allocator_destructor<_Ap> _Dp;
1818 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1819 ::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), allocator<_FR>(__a));
1820 __f_ = __hold.release();
1824 template<class _Rp, class ..._ArgTypes>
1825 template <class _Fp, class _Alloc>
1826 __packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(
1827 allocator_arg_t, const _Alloc& __a0, _Fp&& __f)
1830 typedef allocator_traits<_Alloc> __alloc_traits;
1831 typedef typename remove_reference<_Fp>::type _FR;
1832 typedef __packaged_task_func<_FR, _Alloc, _Rp(_ArgTypes...)> _FF;
1833 if (sizeof(_FF) <= sizeof(__buf_))
1835 __f_ = (__base*)&__buf_;
1836 ::new (__f_) _FF(_VSTD::forward<_Fp>(__f));
1840 typedef typename __alloc_traits::template
1841 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1844 rebind_alloc<_FF>::other
1848 typedef __allocator_destructor<_Ap> _Dp;
1849 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1850 ::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), _Alloc(__a));
1851 __f_ = __hold.release();
1855 template<class _Rp, class ..._ArgTypes>
1856 __packaged_task_function<_Rp(_ArgTypes...)>&
1857 __packaged_task_function<_Rp(_ArgTypes...)>::operator=(__packaged_task_function&& __f)
1859 if (__f_ == (__base*)&__buf_)
1862 __f_->destroy_deallocate();
1864 if (__f.__f_ == nullptr)
1866 else if (__f.__f_ == (__base*)&__f.__buf_)
1868 __f_ = (__base*)&__buf_;
1869 __f.__f_->__move_to(__f_);
1878 template<class _Rp, class ..._ArgTypes>
1879 __packaged_task_function<_Rp(_ArgTypes...)>::~__packaged_task_function()
1881 if (__f_ == (__base*)&__buf_)
1884 __f_->destroy_deallocate();
1887 template<class _Rp, class ..._ArgTypes>
1889 __packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f)
1891 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1893 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1894 __base* __t = (__base*)&__tempbuf;
1895 __f_->__move_to(__t);
1898 __f.__f_->__move_to((__base*)&__buf_);
1899 __f.__f_->destroy();
1901 __f_ = (__base*)&__buf_;
1902 __t->__move_to((__base*)&__f.__buf_);
1904 __f.__f_ = (__base*)&__f.__buf_;
1906 else if (__f_ == (__base*)&__buf_)
1908 __f_->__move_to((__base*)&__f.__buf_);
1911 __f.__f_ = (__base*)&__f.__buf_;
1913 else if (__f.__f_ == (__base*)&__f.__buf_)
1915 __f.__f_->__move_to((__base*)&__buf_);
1916 __f.__f_->destroy();
1918 __f_ = (__base*)&__buf_;
1921 _VSTD::swap(__f_, __f.__f_);
1924 template<class _Rp, class ..._ArgTypes>
1925 inline _LIBCPP_INLINE_VISIBILITY
1927 __packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1929 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
1932 template<class _Rp, class ..._ArgTypes>
1933 class _LIBCPP_VISIBLE packaged_task<_Rp(_ArgTypes...)>
1936 typedef _Rp result_type;
1939 __packaged_task_function<result_type(_ArgTypes...)> __f_;
1940 promise<result_type> __p_;
1943 // construction and destruction
1944 _LIBCPP_INLINE_VISIBILITY
1945 packaged_task() : __p_(nullptr) {}
1946 template <class _Fp>
1947 _LIBCPP_INLINE_VISIBILITY
1948 explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
1949 template <class _Fp, class _Allocator>
1950 _LIBCPP_INLINE_VISIBILITY
1951 explicit packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
1952 : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
1953 __p_(allocator_arg, __a) {}
1954 // ~packaged_task() = default;
1957 packaged_task(packaged_task&) = delete;
1958 packaged_task& operator=(packaged_task&) = delete;
1961 _LIBCPP_INLINE_VISIBILITY
1962 packaged_task(packaged_task&& __other)
1963 : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
1964 _LIBCPP_INLINE_VISIBILITY
1965 packaged_task& operator=(packaged_task&& __other)
1967 __f_ = _VSTD::move(__other.__f_);
1968 __p_ = _VSTD::move(__other.__p_);
1971 _LIBCPP_INLINE_VISIBILITY
1972 void swap(packaged_task& __other)
1974 __f_.swap(__other.__f_);
1975 __p_.swap(__other.__p_);
1978 _LIBCPP_INLINE_VISIBILITY
1979 bool valid() const {return __p_.__state_ != nullptr;}
1982 _LIBCPP_INLINE_VISIBILITY
1983 future<result_type> get_future() {return __p_.get_future();}
1986 void operator()(_ArgTypes... __args);
1987 void make_ready_at_thread_exit(_ArgTypes... __args);
1992 template<class _Rp, class ..._ArgTypes>
1994 packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args)
1996 #ifndef _LIBCPP_NO_EXCEPTIONS
1997 if (__p_.__state_ == nullptr)
1998 throw future_error(make_error_code(future_errc::no_state));
1999 if (__p_.__state_->__has_value())
2000 throw future_error(make_error_code(future_errc::promise_already_satisfied));
2003 #endif // _LIBCPP_NO_EXCEPTIONS
2004 __p_.set_value(__f_(_VSTD::forward<_ArgTypes>(__args)...));
2005 #ifndef _LIBCPP_NO_EXCEPTIONS
2009 __p_.set_exception(current_exception());
2011 #endif // _LIBCPP_NO_EXCEPTIONS
2014 template<class _Rp, class ..._ArgTypes>
2016 packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
2018 #ifndef _LIBCPP_NO_EXCEPTIONS
2019 if (__p_.__state_ == nullptr)
2020 throw future_error(make_error_code(future_errc::no_state));
2021 if (__p_.__state_->__has_value())
2022 throw future_error(make_error_code(future_errc::promise_already_satisfied));
2025 #endif // _LIBCPP_NO_EXCEPTIONS
2026 __p_.set_value_at_thread_exit(__f_(_VSTD::forward<_ArgTypes>(__args)...));
2027 #ifndef _LIBCPP_NO_EXCEPTIONS
2031 __p_.set_exception_at_thread_exit(current_exception());
2033 #endif // _LIBCPP_NO_EXCEPTIONS
2036 template<class _Rp, class ..._ArgTypes>
2038 packaged_task<_Rp(_ArgTypes...)>::reset()
2040 #ifndef _LIBCPP_NO_EXCEPTIONS
2042 throw future_error(make_error_code(future_errc::no_state));
2043 #endif // _LIBCPP_NO_EXCEPTIONS
2044 __p_ = promise<result_type>();
2047 template<class ..._ArgTypes>
2048 class _LIBCPP_VISIBLE packaged_task<void(_ArgTypes...)>
2051 typedef void result_type;
2054 __packaged_task_function<result_type(_ArgTypes...)> __f_;
2055 promise<result_type> __p_;
2058 // construction and destruction
2059 _LIBCPP_INLINE_VISIBILITY
2060 packaged_task() : __p_(nullptr) {}
2061 template <class _Fp>
2062 _LIBCPP_INLINE_VISIBILITY
2063 explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
2064 template <class _Fp, class _Allocator>
2065 _LIBCPP_INLINE_VISIBILITY
2066 explicit packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
2067 : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
2068 __p_(allocator_arg, __a) {}
2069 // ~packaged_task() = default;
2072 packaged_task(packaged_task&) = delete;
2073 packaged_task& operator=(packaged_task&) = delete;
2076 _LIBCPP_INLINE_VISIBILITY
2077 packaged_task(packaged_task&& __other)
2078 : __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
2079 _LIBCPP_INLINE_VISIBILITY
2080 packaged_task& operator=(packaged_task&& __other)
2082 __f_ = _VSTD::move(__other.__f_);
2083 __p_ = _VSTD::move(__other.__p_);
2086 _LIBCPP_INLINE_VISIBILITY
2087 void swap(packaged_task& __other)
2089 __f_.swap(__other.__f_);
2090 __p_.swap(__other.__p_);
2093 _LIBCPP_INLINE_VISIBILITY
2094 bool valid() const {return __p_.__state_ != nullptr;}
2097 _LIBCPP_INLINE_VISIBILITY
2098 future<result_type> get_future() {return __p_.get_future();}
2101 void operator()(_ArgTypes... __args);
2102 void make_ready_at_thread_exit(_ArgTypes... __args);
2107 template<class ..._ArgTypes>
2109 packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args)
2111 #ifndef _LIBCPP_NO_EXCEPTIONS
2112 if (__p_.__state_ == nullptr)
2113 throw future_error(make_error_code(future_errc::no_state));
2114 if (__p_.__state_->__has_value())
2115 throw future_error(make_error_code(future_errc::promise_already_satisfied));
2118 #endif // _LIBCPP_NO_EXCEPTIONS
2119 __f_(_VSTD::forward<_ArgTypes>(__args)...);
2121 #ifndef _LIBCPP_NO_EXCEPTIONS
2125 __p_.set_exception(current_exception());
2127 #endif // _LIBCPP_NO_EXCEPTIONS
2130 template<class ..._ArgTypes>
2132 packaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
2134 #ifndef _LIBCPP_NO_EXCEPTIONS
2135 if (__p_.__state_ == nullptr)
2136 throw future_error(make_error_code(future_errc::no_state));
2137 if (__p_.__state_->__has_value())
2138 throw future_error(make_error_code(future_errc::promise_already_satisfied));
2141 #endif // _LIBCPP_NO_EXCEPTIONS
2142 __f_(_VSTD::forward<_ArgTypes>(__args)...);
2143 __p_.set_value_at_thread_exit();
2144 #ifndef _LIBCPP_NO_EXCEPTIONS
2148 __p_.set_exception_at_thread_exit(current_exception());
2150 #endif // _LIBCPP_NO_EXCEPTIONS
2153 template<class ..._ArgTypes>
2155 packaged_task<void(_ArgTypes...)>::reset()
2157 #ifndef _LIBCPP_NO_EXCEPTIONS
2159 throw future_error(make_error_code(future_errc::no_state));
2160 #endif // _LIBCPP_NO_EXCEPTIONS
2161 __p_ = promise<result_type>();
2164 template <class _Callable>
2165 inline _LIBCPP_INLINE_VISIBILITY
2167 swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y)
2172 template <class _Callable, class _Alloc>
2173 struct _LIBCPP_VISIBLE uses_allocator<packaged_task<_Callable>, _Alloc>
2174 : public true_type {};
2176 template <class _Rp, class _Fp>
2178 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2179 __make_deferred_assoc_state(_Fp&& __f)
2181 __make_deferred_assoc_state(_Fp __f)
2184 unique_ptr<__deferred_assoc_state<_Rp, _Fp>, __release_shared_count>
2185 __h(new __deferred_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f)));
2186 return future<_Rp>(__h.get());
2189 template <class _Rp, class _Fp>
2191 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2192 __make_async_assoc_state(_Fp&& __f)
2194 __make_async_assoc_state(_Fp __f)
2197 unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count>
2198 __h(new __async_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f)));
2199 _VSTD::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach();
2200 return future<_Rp>(__h.get());
2203 template <class _Fp, class... _Args>
2206 tuple<_Fp, _Args...> __f_;
2209 typedef typename __invoke_of<_Fp, _Args...>::type _Rp;
2211 _LIBCPP_INLINE_VISIBILITY
2212 explicit __async_func(_Fp&& __f, _Args&&... __args)
2213 : __f_(_VSTD::move(__f), _VSTD::move(__args)...) {}
2215 _LIBCPP_INLINE_VISIBILITY
2216 __async_func(__async_func&& __f) : __f_(_VSTD::move(__f.__f_)) {}
2220 typedef typename __make_tuple_indices<1+sizeof...(_Args), 1>::type _Index;
2221 return __execute(_Index());
2224 template <size_t ..._Indices>
2226 __execute(__tuple_indices<_Indices...>)
2228 return __invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...);
2232 template <class _Fp, class... _Args>
2233 future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type>
2234 async(launch __policy, _Fp&& __f, _Args&&... __args)
2236 typedef __async_func<typename decay<_Fp>::type, typename decay<_Args>::type...> _BF;
2237 typedef typename _BF::_Rp _Rp;
2239 if (int(__policy) & int(launch::async))
2240 __r = _VSTD::__make_async_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)),
2241 __decay_copy(_VSTD::forward<_Args>(__args))...));
2242 else if (int(__policy) & int(launch::deferred))
2243 __r = _VSTD::__make_deferred_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)),
2244 __decay_copy(_VSTD::forward<_Args>(__args))...));
2248 template <class _Fp, class... _Args>
2249 inline _LIBCPP_INLINE_VISIBILITY
2250 future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type>
2251 async(_Fp&& __f, _Args&&... __args)
2253 return _VSTD::async(launch::any, _VSTD::forward<_Fp>(__f),
2254 _VSTD::forward<_Args>(__args)...);
2257 #endif // _LIBCPP_HAS_NO_VARIADICS
2261 template <class _Rp>
2262 class _LIBCPP_VISIBLE shared_future
2264 __assoc_state<_Rp>* __state_;
2267 _LIBCPP_INLINE_VISIBILITY
2268 shared_future() : __state_(nullptr) {}
2269 _LIBCPP_INLINE_VISIBILITY
2270 shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
2271 {if (__state_) __state_->__add_shared();}
2272 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2273 _LIBCPP_INLINE_VISIBILITY
2274 shared_future(future<_Rp>&& __f) : __state_(__f.__state_)
2275 {__f.__state_ = nullptr;}
2276 _LIBCPP_INLINE_VISIBILITY
2277 shared_future(shared_future&& __rhs) : __state_(__rhs.__state_)
2278 {__rhs.__state_ = nullptr;}
2279 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2281 shared_future& operator=(const shared_future& __rhs);
2282 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2283 _LIBCPP_INLINE_VISIBILITY
2284 shared_future& operator=(shared_future&& __rhs)
2286 shared_future(std::move(__rhs)).swap(*this);
2289 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2291 // retrieving the value
2292 _LIBCPP_INLINE_VISIBILITY
2293 const _Rp& get() const {return __state_->copy();}
2295 _LIBCPP_INLINE_VISIBILITY
2296 void swap(shared_future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
2298 // functions to check state
2299 _LIBCPP_INLINE_VISIBILITY
2300 bool valid() const {return __state_ != nullptr;}
2302 _LIBCPP_INLINE_VISIBILITY
2303 void wait() const {__state_->wait();}
2304 template <class _Rep, class _Period>
2305 _LIBCPP_INLINE_VISIBILITY
2307 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
2308 {return __state_->wait_for(__rel_time);}
2309 template <class _Clock, class _Duration>
2310 _LIBCPP_INLINE_VISIBILITY
2312 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
2313 {return __state_->wait_until(__abs_time);}
2316 template <class _Rp>
2317 shared_future<_Rp>::~shared_future()
2320 __state_->__release_shared();
2323 template <class _Rp>
2325 shared_future<_Rp>::operator=(const shared_future& __rhs)
2328 __rhs.__state_->__add_shared();
2330 __state_->__release_shared();
2331 __state_ = __rhs.__state_;
2335 template <class _Rp>
2336 class _LIBCPP_VISIBLE shared_future<_Rp&>
2338 __assoc_state<_Rp&>* __state_;
2341 _LIBCPP_INLINE_VISIBILITY
2342 shared_future() : __state_(nullptr) {}
2343 _LIBCPP_INLINE_VISIBILITY
2344 shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
2345 {if (__state_) __state_->__add_shared();}
2346 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2347 _LIBCPP_INLINE_VISIBILITY
2348 shared_future(future<_Rp&>&& __f) : __state_(__f.__state_)
2349 {__f.__state_ = nullptr;}
2350 _LIBCPP_INLINE_VISIBILITY
2351 shared_future(shared_future&& __rhs) : __state_(__rhs.__state_)
2352 {__rhs.__state_ = nullptr;}
2353 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2355 shared_future& operator=(const shared_future& __rhs);
2356 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2357 _LIBCPP_INLINE_VISIBILITY
2358 shared_future& operator=(shared_future&& __rhs)
2360 shared_future(std::move(__rhs)).swap(*this);
2363 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2365 // retrieving the value
2366 _LIBCPP_INLINE_VISIBILITY
2367 _Rp& get() const {return __state_->copy();}
2369 _LIBCPP_INLINE_VISIBILITY
2370 void swap(shared_future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
2372 // functions to check state
2373 _LIBCPP_INLINE_VISIBILITY
2374 bool valid() const {return __state_ != nullptr;}
2376 _LIBCPP_INLINE_VISIBILITY
2377 void wait() const {__state_->wait();}
2378 template <class _Rep, class _Period>
2379 _LIBCPP_INLINE_VISIBILITY
2381 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
2382 {return __state_->wait_for(__rel_time);}
2383 template <class _Clock, class _Duration>
2384 _LIBCPP_INLINE_VISIBILITY
2386 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
2387 {return __state_->wait_until(__abs_time);}
2390 template <class _Rp>
2391 shared_future<_Rp&>::~shared_future()
2394 __state_->__release_shared();
2397 template <class _Rp>
2398 shared_future<_Rp&>&
2399 shared_future<_Rp&>::operator=(const shared_future& __rhs)
2402 __rhs.__state_->__add_shared();
2404 __state_->__release_shared();
2405 __state_ = __rhs.__state_;
2410 class _LIBCPP_VISIBLE shared_future<void>
2412 __assoc_sub_state* __state_;
2415 _LIBCPP_INLINE_VISIBILITY
2416 shared_future() : __state_(nullptr) {}
2417 _LIBCPP_INLINE_VISIBILITY
2418 shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
2419 {if (__state_) __state_->__add_shared();}
2420 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2421 _LIBCPP_INLINE_VISIBILITY
2422 shared_future(future<void>&& __f) : __state_(__f.__state_)
2423 {__f.__state_ = nullptr;}
2424 _LIBCPP_INLINE_VISIBILITY
2425 shared_future(shared_future&& __rhs) : __state_(__rhs.__state_)
2426 {__rhs.__state_ = nullptr;}
2427 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2429 shared_future& operator=(const shared_future& __rhs);
2430 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2431 _LIBCPP_INLINE_VISIBILITY
2432 shared_future& operator=(shared_future&& __rhs)
2434 shared_future(std::move(__rhs)).swap(*this);
2437 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2439 // retrieving the value
2440 _LIBCPP_INLINE_VISIBILITY
2441 void get() const {__state_->copy();}
2443 _LIBCPP_INLINE_VISIBILITY
2444 void swap(shared_future& __rhs) {_VSTD::swap(__state_, __rhs.__state_);}
2446 // functions to check state
2447 _LIBCPP_INLINE_VISIBILITY
2448 bool valid() const {return __state_ != nullptr;}
2450 _LIBCPP_INLINE_VISIBILITY
2451 void wait() const {__state_->wait();}
2452 template <class _Rep, class _Period>
2453 _LIBCPP_INLINE_VISIBILITY
2455 wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
2456 {return __state_->wait_for(__rel_time);}
2457 template <class _Clock, class _Duration>
2458 _LIBCPP_INLINE_VISIBILITY
2460 wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
2461 {return __state_->wait_until(__abs_time);}
2464 template <class _Rp>
2465 inline _LIBCPP_INLINE_VISIBILITY
2467 swap(shared_future<_Rp>& __x, shared_future<_Rp>& __y)
2472 template <class _Rp>
2473 inline _LIBCPP_INLINE_VISIBILITY
2475 future<_Rp>::share()
2477 return shared_future<_Rp>(_VSTD::move(*this));
2480 template <class _Rp>
2481 inline _LIBCPP_INLINE_VISIBILITY
2483 future<_Rp&>::share()
2485 return shared_future<_Rp&>(_VSTD::move(*this));
2488 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2490 inline _LIBCPP_INLINE_VISIBILITY
2492 future<void>::share()
2494 return shared_future<void>(_VSTD::move(*this));
2497 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2499 _LIBCPP_END_NAMESPACE_STD
2501 #endif // _LIBCPP_FUTURE