libstdc++
future
Go to the documentation of this file.
1 // <future> -*- C++ -*-
2 
3 // Copyright (C) 2009-2014 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /** @file include/future
26  * This is a Standard C++ Library header.
27  */
28 
29 #ifndef _GLIBCXX_FUTURE
30 #define _GLIBCXX_FUTURE 1
31 
32 #pragma GCC system_header
33 
34 #if __cplusplus < 201103L
35 # include <bits/c++0x_warning.h>
36 #else
37 
38 #include <functional>
39 #include <mutex>
40 #include <thread>
41 #include <condition_variable>
42 #include <system_error>
43 #include <atomic>
44 #include <bits/functexcept.h>
45 #include <bits/unique_ptr.h>
46 #include <bits/shared_ptr.h>
47 #include <bits/uses_allocator.h>
48 #include <bits/alloc_traits.h>
49 #include <ext/aligned_buffer.h>
50 
51 namespace std _GLIBCXX_VISIBILITY(default)
52 {
53 _GLIBCXX_BEGIN_NAMESPACE_VERSION
54 
55  /**
56  * @defgroup futures Futures
57  * @ingroup concurrency
58  *
59  * Classes for futures support.
60  * @{
61  */
62 
63  /// Error code for futures
64  enum class future_errc
65  {
66  future_already_retrieved = 1,
67  promise_already_satisfied,
68  no_state,
69  broken_promise
70  };
71 
72  /// Specialization.
73  template<>
75 
76  /// Points to a statically-allocated object derived from error_category.
77  const error_category&
78  future_category() noexcept;
79 
80  /// Overload for make_error_code.
81  inline error_code
82  make_error_code(future_errc __errc) noexcept
83  { return error_code(static_cast<int>(__errc), future_category()); }
84 
85  /// Overload for make_error_condition.
86  inline error_condition
87  make_error_condition(future_errc __errc) noexcept
88  { return error_condition(static_cast<int>(__errc), future_category()); }
89 
90  /**
91  * @brief Exception type thrown by futures.
92  * @ingroup exceptions
93  */
94  class future_error : public logic_error
95  {
96  error_code _M_code;
97 
98  public:
99  explicit future_error(error_code __ec)
100  : logic_error("std::future_error"), _M_code(__ec)
101  { }
102 
103  virtual ~future_error() noexcept;
104 
105  virtual const char*
106  what() const noexcept;
107 
108  const error_code&
109  code() const noexcept { return _M_code; }
110  };
111 
112  // Forward declarations.
113  template<typename _Res>
114  class future;
115 
116  template<typename _Res>
117  class shared_future;
118 
119  template<typename _Signature>
120  class packaged_task;
121 
122  template<typename _Res>
123  class promise;
124 
125  /// Launch code for futures
126  enum class launch
127  {
128  async = 1,
129  deferred = 2
130  };
131 
132  constexpr launch operator&(launch __x, launch __y)
133  {
134  return static_cast<launch>(
135  static_cast<int>(__x) & static_cast<int>(__y));
136  }
137 
138  constexpr launch operator|(launch __x, launch __y)
139  {
140  return static_cast<launch>(
141  static_cast<int>(__x) | static_cast<int>(__y));
142  }
143 
144  constexpr launch operator^(launch __x, launch __y)
145  {
146  return static_cast<launch>(
147  static_cast<int>(__x) ^ static_cast<int>(__y));
148  }
149 
150  constexpr launch operator~(launch __x)
151  { return static_cast<launch>(~static_cast<int>(__x)); }
152 
153  inline launch& operator&=(launch& __x, launch __y)
154  { return __x = __x & __y; }
155 
156  inline launch& operator|=(launch& __x, launch __y)
157  { return __x = __x | __y; }
158 
159  inline launch& operator^=(launch& __x, launch __y)
160  { return __x = __x ^ __y; }
161 
162  /// Status code for futures
163  enum class future_status
164  {
165  ready,
166  timeout,
167  deferred
168  };
169 
170  template<typename _Fn, typename... _Args>
171  future<typename result_of<_Fn(_Args...)>::type>
172  async(launch __policy, _Fn&& __fn, _Args&&... __args);
173 
174  template<typename _Fn, typename... _Args>
175  future<typename result_of<_Fn(_Args...)>::type>
176  async(_Fn&& __fn, _Args&&... __args);
177 
178 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \
179  && (ATOMIC_INT_LOCK_FREE > 1)
180 
181  /// Base class and enclosing scope.
182  struct __future_base
183  {
184  /// Base class for results.
185  struct _Result_base
186  {
187  exception_ptr _M_error;
188 
189  _Result_base(const _Result_base&) = delete;
190  _Result_base& operator=(const _Result_base&) = delete;
191 
192  // _M_destroy() allows derived classes to control deallocation
193  virtual void _M_destroy() = 0;
194 
195  struct _Deleter
196  {
197  void operator()(_Result_base* __fr) const { __fr->_M_destroy(); }
198  };
199 
200  protected:
201  _Result_base();
202  virtual ~_Result_base();
203  };
204 
205  /// Result.
206  template<typename _Res>
207  struct _Result : _Result_base
208  {
209  private:
210  __gnu_cxx::__aligned_buffer<_Res> _M_storage;
211  bool _M_initialized;
212 
213  public:
214  typedef _Res result_type;
215 
216  _Result() noexcept : _M_initialized() { }
217 
218  ~_Result()
219  {
220  if (_M_initialized)
221  _M_value().~_Res();
222  }
223 
224  // Return lvalue, future will add const or rvalue-reference
225  _Res&
226  _M_value() noexcept { return *_M_storage._M_ptr(); }
227 
228  void
229  _M_set(const _Res& __res)
230  {
231  ::new (_M_storage._M_addr()) _Res(__res);
232  _M_initialized = true;
233  }
234 
235  void
236  _M_set(_Res&& __res)
237  {
238  ::new (_M_storage._M_addr()) _Res(std::move(__res));
239  _M_initialized = true;
240  }
241 
242  private:
243  void _M_destroy() { delete this; }
244  };
245 
246  /// A unique_ptr based on the instantiating type.
247  template<typename _Res>
248  using _Ptr = unique_ptr<_Res, _Result_base::_Deleter>;
249 
250  /// Result_alloc.
251  template<typename _Res, typename _Alloc>
252  struct _Result_alloc final : _Result<_Res>, _Alloc
253  {
254  typedef typename allocator_traits<_Alloc>::template
255  rebind_alloc<_Result_alloc> __allocator_type;
256 
257  explicit
258  _Result_alloc(const _Alloc& __a) : _Result<_Res>(), _Alloc(__a)
259  { }
260 
261  private:
262  void _M_destroy()
263  {
264  typedef allocator_traits<__allocator_type> __traits;
265  __allocator_type __a(*this);
266  __traits::destroy(__a, this);
267  __traits::deallocate(__a, this, 1);
268  }
269  };
270 
271  template<typename _Res, typename _Allocator>
272  static _Ptr<_Result_alloc<_Res, _Allocator>>
273  _S_allocate_result(const _Allocator& __a)
274  {
275  typedef _Result_alloc<_Res, _Allocator> __result_type;
276  typedef allocator_traits<typename __result_type::__allocator_type>
277  __traits;
278  typename __traits::allocator_type __a2(__a);
279  __result_type* __p = __traits::allocate(__a2, 1);
280  __try
281  {
282  __traits::construct(__a2, __p, __a);
283  }
284  __catch(...)
285  {
286  __traits::deallocate(__a2, __p, 1);
287  __throw_exception_again;
288  }
289  return _Ptr<__result_type>(__p);
290  }
291 
292  template<typename _Res, typename _Tp>
293  static _Ptr<_Result<_Res>>
294  _S_allocate_result(const std::allocator<_Tp>& __a)
295  {
296  return _Ptr<_Result<_Res>>(new _Result<_Res>);
297  }
298 
299  /// Base class for state between a promise and one or more
300  /// associated futures.
301  class _State_baseV2
302  {
303  typedef _Ptr<_Result_base> _Ptr_type;
304 
305  _Ptr_type _M_result;
306  mutex _M_mutex;
307  condition_variable _M_cond;
308  atomic_flag _M_retrieved;
309  once_flag _M_once;
310 
311  public:
312  _State_baseV2() noexcept : _M_result(), _M_retrieved(ATOMIC_FLAG_INIT)
313  { }
314  _State_baseV2(const _State_baseV2&) = delete;
315  _State_baseV2& operator=(const _State_baseV2&) = delete;
316  virtual ~_State_baseV2() = default;
317 
318  _Result_base&
319  wait()
320  {
321  _M_complete_async();
322  unique_lock<mutex> __lock(_M_mutex);
323  _M_cond.wait(__lock, [&] { return _M_ready(); });
324  return *_M_result;
325  }
326 
327  template<typename _Rep, typename _Period>
329  wait_for(const chrono::duration<_Rep, _Period>& __rel)
330  {
331  unique_lock<mutex> __lock(_M_mutex);
332  if (_M_ready())
333  return future_status::ready;
334  if (_M_has_deferred())
335  return future_status::deferred;
336  if (_M_cond.wait_for(__lock, __rel, [&] { return _M_ready(); }))
337  {
338  // _GLIBCXX_RESOLVE_LIB_DEFECTS
339  // 2100. timed waiting functions must also join
340  _M_complete_async();
341  return future_status::ready;
342  }
343  return future_status::timeout;
344  }
345 
346  template<typename _Clock, typename _Duration>
348  wait_until(const chrono::time_point<_Clock, _Duration>& __abs)
349  {
350  unique_lock<mutex> __lock(_M_mutex);
351  if (_M_ready())
352  return future_status::ready;
353  if (_M_has_deferred())
354  return future_status::deferred;
355  if (_M_cond.wait_until(__lock, __abs, [&] { return _M_ready(); }))
356  {
357  // _GLIBCXX_RESOLVE_LIB_DEFECTS
358  // 2100. timed waiting functions must also join
359  _M_complete_async();
360  return future_status::ready;
361  }
362  return future_status::timeout;
363  }
364 
365  void
366  _M_set_result(function<_Ptr_type()> __res, bool __ignore_failure = false)
367  {
368  bool __set = __ignore_failure;
369  // all calls to this function are serialized,
370  // side-effects of invoking __res only happen once
371  call_once(_M_once, &_State_baseV2::_M_do_set, this, ref(__res),
372  ref(__set));
373  if (!__set)
374  __throw_future_error(int(future_errc::promise_already_satisfied));
375  }
376 
377  void
378  _M_break_promise(_Ptr_type __res)
379  {
380  if (static_cast<bool>(__res))
381  {
382  error_code __ec(make_error_code(future_errc::broken_promise));
383  __res->_M_error = make_exception_ptr(future_error(__ec));
384  {
385  lock_guard<mutex> __lock(_M_mutex);
386  _M_result.swap(__res);
387  }
388  _M_cond.notify_all();
389  }
390  }
391 
392  // Called when this object is passed to a future.
393  void
394  _M_set_retrieved_flag()
395  {
396  if (_M_retrieved.test_and_set())
397  __throw_future_error(int(future_errc::future_already_retrieved));
398  }
399 
400  template<typename _Res, typename _Arg>
401  struct _Setter;
402 
403  // set lvalues
404  template<typename _Res, typename _Arg>
405  struct _Setter<_Res, _Arg&>
406  {
407  // check this is only used by promise<R>::set_value(const R&)
408  // or promise<R>::set_value(R&)
409  static_assert(is_same<_Res, _Arg&>::value // promise<R&>
410  || is_same<const _Res, _Arg>::value, // promise<R>
411  "Invalid specialisation");
412 
413  typename promise<_Res>::_Ptr_type operator()()
414  {
415  _State_baseV2::_S_check(_M_promise->_M_future);
416  _M_promise->_M_storage->_M_set(_M_arg);
417  return std::move(_M_promise->_M_storage);
418  }
419  promise<_Res>* _M_promise;
420  _Arg& _M_arg;
421  };
422 
423  // set rvalues
424  template<typename _Res>
425  struct _Setter<_Res, _Res&&>
426  {
427  typename promise<_Res>::_Ptr_type operator()()
428  {
429  _State_baseV2::_S_check(_M_promise->_M_future);
430  _M_promise->_M_storage->_M_set(std::move(_M_arg));
431  return std::move(_M_promise->_M_storage);
432  }
433  promise<_Res>* _M_promise;
434  _Res& _M_arg;
435  };
436 
437  struct __exception_ptr_tag { };
438 
439  // set exceptions
440  template<typename _Res>
441  struct _Setter<_Res, __exception_ptr_tag>
442  {
443  typename promise<_Res>::_Ptr_type operator()()
444  {
445  _State_baseV2::_S_check(_M_promise->_M_future);
446  _M_promise->_M_storage->_M_error = _M_ex;
447  return std::move(_M_promise->_M_storage);
448  }
449 
450  promise<_Res>* _M_promise;
451  exception_ptr& _M_ex;
452  };
453 
454  template<typename _Res, typename _Arg>
455  static _Setter<_Res, _Arg&&>
456  __setter(promise<_Res>* __prom, _Arg&& __arg)
457  {
458  return _Setter<_Res, _Arg&&>{ __prom, __arg };
459  }
460 
461  template<typename _Res>
462  static _Setter<_Res, __exception_ptr_tag>
463  __setter(exception_ptr& __ex, promise<_Res>* __prom)
464  {
465  return _Setter<_Res, __exception_ptr_tag>{ __prom, __ex };
466  }
467 
468  static _Setter<void, void>
469  __setter(promise<void>* __prom);
470 
471  template<typename _Tp>
472  static void
473  _S_check(const shared_ptr<_Tp>& __p)
474  {
475  if (!static_cast<bool>(__p))
476  __throw_future_error((int)future_errc::no_state);
477  }
478 
479  private:
480  void
481  _M_do_set(function<_Ptr_type()>& __f, bool& __set)
482  {
483  _Ptr_type __res = __f();
484  {
485  lock_guard<mutex> __lock(_M_mutex);
486  _M_result.swap(__res);
487  }
488  _M_cond.notify_all();
489  __set = true;
490  }
491 
492  bool _M_ready() const noexcept { return static_cast<bool>(_M_result); }
493 
494  // Wait for completion of async function.
495  virtual void _M_complete_async() { }
496 
497  // Return true if state contains a deferred function.
498  virtual bool _M_has_deferred() const { return false; }
499  };
500 
501 #ifdef _GLIBCXX_ASYNC_ABI_COMPAT
502  class _State_base;
503  class _Async_state_common;
504 #else
505  using _State_base = _State_baseV2;
506  class _Async_state_commonV2;
507 #endif
508 
509  template<typename _BoundFn, typename = typename _BoundFn::result_type>
510  class _Deferred_state;
511 
512  template<typename _BoundFn, typename = typename _BoundFn::result_type>
513  class _Async_state_impl;
514 
515  template<typename _Signature>
516  class _Task_state_base;
517 
518  template<typename _Fn, typename _Alloc, typename _Signature>
519  class _Task_state;
520 
521  template<typename _BoundFn>
523  _S_make_deferred_state(_BoundFn&& __fn);
524 
525  template<typename _BoundFn>
527  _S_make_async_state(_BoundFn&& __fn);
528 
529  template<typename _Res_ptr,
530  typename _Res = typename _Res_ptr::element_type::result_type>
531  struct _Task_setter;
532 
533  template<typename _Res_ptr, typename _BoundFn>
534  static _Task_setter<_Res_ptr>
535  _S_task_setter(_Res_ptr& __ptr, _BoundFn&& __call)
536  {
537  return _Task_setter<_Res_ptr>{ __ptr, std::ref(__call) };
538  }
539  };
540 
541  /// Partial specialization for reference types.
542  template<typename _Res>
543  struct __future_base::_Result<_Res&> : __future_base::_Result_base
544  {
545  typedef _Res& result_type;
546 
547  _Result() noexcept : _M_value_ptr() { }
548 
549  void _M_set(_Res& __res) noexcept { _M_value_ptr = &__res; }
550 
551  _Res& _M_get() noexcept { return *_M_value_ptr; }
552 
553  private:
554  _Res* _M_value_ptr;
555 
556  void _M_destroy() { delete this; }
557  };
558 
559  /// Explicit specialization for void.
560  template<>
561  struct __future_base::_Result<void> : __future_base::_Result_base
562  {
563  typedef void result_type;
564 
565  private:
566  void _M_destroy() { delete this; }
567  };
568 
569 #ifndef _GLIBCXX_ASYNC_ABI_COMPAT
570 
571  /// Common implementation for future and shared_future.
572  template<typename _Res>
573  class __basic_future : public __future_base
574  {
575  protected:
576  typedef shared_ptr<_State_base> __state_type;
577  typedef __future_base::_Result<_Res>& __result_type;
578 
579  private:
580  __state_type _M_state;
581 
582  public:
583  // Disable copying.
584  __basic_future(const __basic_future&) = delete;
585  __basic_future& operator=(const __basic_future&) = delete;
586 
587  bool
588  valid() const noexcept { return static_cast<bool>(_M_state); }
589 
590  void
591  wait() const
592  {
593  _State_base::_S_check(_M_state);
594  _M_state->wait();
595  }
596 
597  template<typename _Rep, typename _Period>
599  wait_for(const chrono::duration<_Rep, _Period>& __rel) const
600  {
601  _State_base::_S_check(_M_state);
602  return _M_state->wait_for(__rel);
603  }
604 
605  template<typename _Clock, typename _Duration>
607  wait_until(const chrono::time_point<_Clock, _Duration>& __abs) const
608  {
609  _State_base::_S_check(_M_state);
610  return _M_state->wait_until(__abs);
611  }
612 
613  protected:
614  /// Wait for the state to be ready and rethrow any stored exception
615  __result_type
616  _M_get_result() const
617  {
618  _State_base::_S_check(_M_state);
619  _Result_base& __res = _M_state->wait();
620  if (!(__res._M_error == 0))
621  rethrow_exception(__res._M_error);
622  return static_cast<__result_type>(__res);
623  }
624 
625  void _M_swap(__basic_future& __that) noexcept
626  {
627  _M_state.swap(__that._M_state);
628  }
629 
630  // Construction of a future by promise::get_future()
631  explicit
632  __basic_future(const __state_type& __state) : _M_state(__state)
633  {
634  _State_base::_S_check(_M_state);
635  _M_state->_M_set_retrieved_flag();
636  }
637 
638  // Copy construction from a shared_future
639  explicit
640  __basic_future(const shared_future<_Res>&) noexcept;
641 
642  // Move construction from a shared_future
643  explicit
644  __basic_future(shared_future<_Res>&&) noexcept;
645 
646  // Move construction from a future
647  explicit
648  __basic_future(future<_Res>&&) noexcept;
649 
650  constexpr __basic_future() noexcept : _M_state() { }
651 
652  struct _Reset
653  {
654  explicit _Reset(__basic_future& __fut) noexcept : _M_fut(__fut) { }
655  ~_Reset() { _M_fut._M_state.reset(); }
656  __basic_future& _M_fut;
657  };
658  };
659 
660 
661  /// Primary template for future.
662  template<typename _Res>
663  class future : public __basic_future<_Res>
664  {
665  friend class promise<_Res>;
666  template<typename> friend class packaged_task;
667  template<typename _Fn, typename... _Args>
668  friend future<typename result_of<_Fn(_Args...)>::type>
669  async(launch, _Fn&&, _Args&&...);
670 
671  typedef __basic_future<_Res> _Base_type;
672  typedef typename _Base_type::__state_type __state_type;
673 
674  explicit
675  future(const __state_type& __state) : _Base_type(__state) { }
676 
677  public:
678  constexpr future() noexcept : _Base_type() { }
679 
680  /// Move constructor
681  future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { }
682 
683  // Disable copying
684  future(const future&) = delete;
685  future& operator=(const future&) = delete;
686 
687  future& operator=(future&& __fut) noexcept
688  {
689  future(std::move(__fut))._M_swap(*this);
690  return *this;
691  }
692 
693  /// Retrieving the value
694  _Res
695  get()
696  {
697  typename _Base_type::_Reset __reset(*this);
698  return std::move(this->_M_get_result()._M_value());
699  }
700 
701  shared_future<_Res> share();
702  };
703 
704  /// Partial specialization for future<R&>
705  template<typename _Res>
706  class future<_Res&> : public __basic_future<_Res&>
707  {
708  friend class promise<_Res&>;
709  template<typename> friend class packaged_task;
710  template<typename _Fn, typename... _Args>
711  friend future<typename result_of<_Fn(_Args...)>::type>
712  async(launch, _Fn&&, _Args&&...);
713 
714  typedef __basic_future<_Res&> _Base_type;
715  typedef typename _Base_type::__state_type __state_type;
716 
717  explicit
718  future(const __state_type& __state) : _Base_type(__state) { }
719 
720  public:
721  constexpr future() noexcept : _Base_type() { }
722 
723  /// Move constructor
724  future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { }
725 
726  // Disable copying
727  future(const future&) = delete;
728  future& operator=(const future&) = delete;
729 
730  future& operator=(future&& __fut) noexcept
731  {
732  future(std::move(__fut))._M_swap(*this);
733  return *this;
734  }
735 
736  /// Retrieving the value
737  _Res&
738  get()
739  {
740  typename _Base_type::_Reset __reset(*this);
741  return this->_M_get_result()._M_get();
742  }
743 
744  shared_future<_Res&> share();
745  };
746 
747  /// Explicit specialization for future<void>
748  template<>
749  class future<void> : public __basic_future<void>
750  {
751  friend class promise<void>;
752  template<typename> friend class packaged_task;
753  template<typename _Fn, typename... _Args>
754  friend future<typename result_of<_Fn(_Args...)>::type>
755  async(launch, _Fn&&, _Args&&...);
756 
757  typedef __basic_future<void> _Base_type;
758  typedef typename _Base_type::__state_type __state_type;
759 
760  explicit
761  future(const __state_type& __state) : _Base_type(__state) { }
762 
763  public:
764  constexpr future() noexcept : _Base_type() { }
765 
766  /// Move constructor
767  future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { }
768 
769  // Disable copying
770  future(const future&) = delete;
771  future& operator=(const future&) = delete;
772 
773  future& operator=(future&& __fut) noexcept
774  {
775  future(std::move(__fut))._M_swap(*this);
776  return *this;
777  }
778 
779  /// Retrieving the value
780  void
781  get()
782  {
783  typename _Base_type::_Reset __reset(*this);
784  this->_M_get_result();
785  }
786 
787  shared_future<void> share();
788  };
789 
790 
791  /// Primary template for shared_future.
792  template<typename _Res>
793  class shared_future : public __basic_future<_Res>
794  {
795  typedef __basic_future<_Res> _Base_type;
796 
797  public:
798  constexpr shared_future() noexcept : _Base_type() { }
799 
800  /// Copy constructor
801  shared_future(const shared_future& __sf) : _Base_type(__sf) { }
802 
803  /// Construct from a future rvalue
804  shared_future(future<_Res>&& __uf) noexcept
805  : _Base_type(std::move(__uf))
806  { }
807 
808  /// Construct from a shared_future rvalue
809  shared_future(shared_future&& __sf) noexcept
810  : _Base_type(std::move(__sf))
811  { }
812 
813  shared_future& operator=(const shared_future& __sf)
814  {
815  shared_future(__sf)._M_swap(*this);
816  return *this;
817  }
818 
819  shared_future& operator=(shared_future&& __sf) noexcept
820  {
821  shared_future(std::move(__sf))._M_swap(*this);
822  return *this;
823  }
824 
825  /// Retrieving the value
826  const _Res&
827  get() const { return this->_M_get_result()._M_value(); }
828  };
829 
830  /// Partial specialization for shared_future<R&>
831  template<typename _Res>
832  class shared_future<_Res&> : public __basic_future<_Res&>
833  {
834  typedef __basic_future<_Res&> _Base_type;
835 
836  public:
837  constexpr shared_future() noexcept : _Base_type() { }
838 
839  /// Copy constructor
840  shared_future(const shared_future& __sf) : _Base_type(__sf) { }
841 
842  /// Construct from a future rvalue
843  shared_future(future<_Res&>&& __uf) noexcept
844  : _Base_type(std::move(__uf))
845  { }
846 
847  /// Construct from a shared_future rvalue
848  shared_future(shared_future&& __sf) noexcept
849  : _Base_type(std::move(__sf))
850  { }
851 
852  shared_future& operator=(const shared_future& __sf)
853  {
854  shared_future(__sf)._M_swap(*this);
855  return *this;
856  }
857 
858  shared_future& operator=(shared_future&& __sf) noexcept
859  {
860  shared_future(std::move(__sf))._M_swap(*this);
861  return *this;
862  }
863 
864  /// Retrieving the value
865  _Res&
866  get() const { return this->_M_get_result()._M_get(); }
867  };
868 
869  /// Explicit specialization for shared_future<void>
870  template<>
871  class shared_future<void> : public __basic_future<void>
872  {
873  typedef __basic_future<void> _Base_type;
874 
875  public:
876  constexpr shared_future() noexcept : _Base_type() { }
877 
878  /// Copy constructor
879  shared_future(const shared_future& __sf) : _Base_type(__sf) { }
880 
881  /// Construct from a future rvalue
882  shared_future(future<void>&& __uf) noexcept
883  : _Base_type(std::move(__uf))
884  { }
885 
886  /// Construct from a shared_future rvalue
887  shared_future(shared_future&& __sf) noexcept
888  : _Base_type(std::move(__sf))
889  { }
890 
891  shared_future& operator=(const shared_future& __sf)
892  {
893  shared_future(__sf)._M_swap(*this);
894  return *this;
895  }
896 
897  shared_future& operator=(shared_future&& __sf) noexcept
898  {
899  shared_future(std::move(__sf))._M_swap(*this);
900  return *this;
901  }
902 
903  // Retrieving the value
904  void
905  get() const { this->_M_get_result(); }
906  };
907 
908  // Now we can define the protected __basic_future constructors.
909  template<typename _Res>
910  inline __basic_future<_Res>::
911  __basic_future(const shared_future<_Res>& __sf) noexcept
912  : _M_state(__sf._M_state)
913  { }
914 
915  template<typename _Res>
916  inline __basic_future<_Res>::
917  __basic_future(shared_future<_Res>&& __sf) noexcept
918  : _M_state(std::move(__sf._M_state))
919  { }
920 
921  template<typename _Res>
922  inline __basic_future<_Res>::
923  __basic_future(future<_Res>&& __uf) noexcept
924  : _M_state(std::move(__uf._M_state))
925  { }
926 
927  template<typename _Res>
928  inline shared_future<_Res>
929  future<_Res>::share()
930  { return shared_future<_Res>(std::move(*this)); }
931 
932  template<typename _Res>
933  inline shared_future<_Res&>
934  future<_Res&>::share()
935  { return shared_future<_Res&>(std::move(*this)); }
936 
937  inline shared_future<void>
938  future<void>::share()
939  { return shared_future<void>(std::move(*this)); }
940 
941  /// Primary template for promise
942  template<typename _Res>
943  class promise
944  {
945  typedef __future_base::_State_base _State;
946  typedef __future_base::_Result<_Res> _Res_type;
947  typedef __future_base::_Ptr<_Res_type> _Ptr_type;
948  template<typename, typename> friend class _State::_Setter;
949 
950  shared_ptr<_State> _M_future;
951  _Ptr_type _M_storage;
952 
953  public:
954  promise()
955  : _M_future(std::make_shared<_State>()),
956  _M_storage(new _Res_type())
957  { }
958 
959  promise(promise&& __rhs) noexcept
960  : _M_future(std::move(__rhs._M_future)),
961  _M_storage(std::move(__rhs._M_storage))
962  { }
963 
964  template<typename _Allocator>
965  promise(allocator_arg_t, const _Allocator& __a)
966  : _M_future(std::allocate_shared<_State>(__a)),
967  _M_storage(__future_base::_S_allocate_result<_Res>(__a))
968  { }
969 
970  template<typename _Allocator>
971  promise(allocator_arg_t, const _Allocator&, promise&& __rhs)
972  : _M_future(std::move(__rhs._M_future)),
973  _M_storage(std::move(__rhs._M_storage))
974  { }
975 
976  promise(const promise&) = delete;
977 
978  ~promise()
979  {
980  if (static_cast<bool>(_M_future) && !_M_future.unique())
981  _M_future->_M_break_promise(std::move(_M_storage));
982  }
983 
984  // Assignment
985  promise&
986  operator=(promise&& __rhs) noexcept
987  {
988  promise(std::move(__rhs)).swap(*this);
989  return *this;
990  }
991 
992  promise& operator=(const promise&) = delete;
993 
994  void
995  swap(promise& __rhs) noexcept
996  {
997  _M_future.swap(__rhs._M_future);
998  _M_storage.swap(__rhs._M_storage);
999  }
1000 
1001  // Retrieving the result
1002  future<_Res>
1003  get_future()
1004  { return future<_Res>(_M_future); }
1005 
1006  // Setting the result
1007  void
1008  set_value(const _Res& __r)
1009  {
1010  auto __setter = _State::__setter(this, __r);
1011  _M_future->_M_set_result(std::move(__setter));
1012  }
1013 
1014  void
1015  set_value(_Res&& __r)
1016  {
1017  auto __setter = _State::__setter(this, std::move(__r));
1018  _M_future->_M_set_result(std::move(__setter));
1019  }
1020 
1021  void
1022  set_exception(exception_ptr __p)
1023  {
1024  auto __setter = _State::__setter(__p, this);
1025  _M_future->_M_set_result(std::move(__setter));
1026  }
1027  };
1028 
1029  template<typename _Res>
1030  inline void
1031  swap(promise<_Res>& __x, promise<_Res>& __y) noexcept
1032  { __x.swap(__y); }
1033 
1034  template<typename _Res, typename _Alloc>
1035  struct uses_allocator<promise<_Res>, _Alloc>
1036  : public true_type { };
1037 
1038 
1039  /// Partial specialization for promise<R&>
1040  template<typename _Res>
1041  class promise<_Res&>
1042  {
1043  typedef __future_base::_State_base _State;
1044  typedef __future_base::_Result<_Res&> _Res_type;
1045  typedef __future_base::_Ptr<_Res_type> _Ptr_type;
1046  template<typename, typename> friend class _State::_Setter;
1047 
1048  shared_ptr<_State> _M_future;
1049  _Ptr_type _M_storage;
1050 
1051  public:
1052  promise()
1053  : _M_future(std::make_shared<_State>()),
1054  _M_storage(new _Res_type())
1055  { }
1056 
1057  promise(promise&& __rhs) noexcept
1058  : _M_future(std::move(__rhs._M_future)),
1059  _M_storage(std::move(__rhs._M_storage))
1060  { }
1061 
1062  template<typename _Allocator>
1063  promise(allocator_arg_t, const _Allocator& __a)
1064  : _M_future(std::allocate_shared<_State>(__a)),
1065  _M_storage(__future_base::_S_allocate_result<_Res&>(__a))
1066  { }
1067 
1068  template<typename _Allocator>
1069  promise(allocator_arg_t, const _Allocator&, promise&& __rhs)
1070  : _M_future(std::move(__rhs._M_future)),
1071  _M_storage(std::move(__rhs._M_storage))
1072  { }
1073 
1074  promise(const promise&) = delete;
1075 
1076  ~promise()
1077  {
1078  if (static_cast<bool>(_M_future) && !_M_future.unique())
1079  _M_future->_M_break_promise(std::move(_M_storage));
1080  }
1081 
1082  // Assignment
1083  promise&
1084  operator=(promise&& __rhs) noexcept
1085  {
1086  promise(std::move(__rhs)).swap(*this);
1087  return *this;
1088  }
1089 
1090  promise& operator=(const promise&) = delete;
1091 
1092  void
1093  swap(promise& __rhs) noexcept
1094  {
1095  _M_future.swap(__rhs._M_future);
1096  _M_storage.swap(__rhs._M_storage);
1097  }
1098 
1099  // Retrieving the result
1100  future<_Res&>
1101  get_future()
1102  { return future<_Res&>(_M_future); }
1103 
1104  // Setting the result
1105  void
1106  set_value(_Res& __r)
1107  {
1108  auto __setter = _State::__setter(this, __r);
1109  _M_future->_M_set_result(std::move(__setter));
1110  }
1111 
1112  void
1113  set_exception(exception_ptr __p)
1114  {
1115  auto __setter = _State::__setter(__p, this);
1116  _M_future->_M_set_result(std::move(__setter));
1117  }
1118  };
1119 
1120  /// Explicit specialization for promise<void>
1121  template<>
1122  class promise<void>
1123  {
1124  typedef __future_base::_State_base _State;
1125  typedef __future_base::_Result<void> _Res_type;
1126  typedef __future_base::_Ptr<_Res_type> _Ptr_type;
1127  template<typename, typename> friend class _State::_Setter;
1128 
1129  shared_ptr<_State> _M_future;
1130  _Ptr_type _M_storage;
1131 
1132  public:
1133  promise()
1134  : _M_future(std::make_shared<_State>()),
1135  _M_storage(new _Res_type())
1136  { }
1137 
1138  promise(promise&& __rhs) noexcept
1139  : _M_future(std::move(__rhs._M_future)),
1140  _M_storage(std::move(__rhs._M_storage))
1141  { }
1142 
1143  template<typename _Allocator>
1144  promise(allocator_arg_t, const _Allocator& __a)
1145  : _M_future(std::allocate_shared<_State>(__a)),
1146  _M_storage(__future_base::_S_allocate_result<void>(__a))
1147  { }
1148 
1149  // _GLIBCXX_RESOLVE_LIB_DEFECTS
1150  // 2095. missing constructors needed for uses-allocator construction
1151  template<typename _Allocator>
1152  promise(allocator_arg_t, const _Allocator&, promise&& __rhs)
1153  : _M_future(std::move(__rhs._M_future)),
1154  _M_storage(std::move(__rhs._M_storage))
1155  { }
1156 
1157  promise(const promise&) = delete;
1158 
1159  ~promise()
1160  {
1161  if (static_cast<bool>(_M_future) && !_M_future.unique())
1162  _M_future->_M_break_promise(std::move(_M_storage));
1163  }
1164 
1165  // Assignment
1166  promise&
1167  operator=(promise&& __rhs) noexcept
1168  {
1169  promise(std::move(__rhs)).swap(*this);
1170  return *this;
1171  }
1172 
1173  promise& operator=(const promise&) = delete;
1174 
1175  void
1176  swap(promise& __rhs) noexcept
1177  {
1178  _M_future.swap(__rhs._M_future);
1179  _M_storage.swap(__rhs._M_storage);
1180  }
1181 
1182  // Retrieving the result
1183  future<void>
1184  get_future()
1185  { return future<void>(_M_future); }
1186 
1187  // Setting the result
1188  void set_value();
1189 
1190  void
1191  set_exception(exception_ptr __p)
1192  {
1193  auto __setter = _State::__setter(__p, this);
1194  _M_future->_M_set_result(std::move(__setter));
1195  }
1196  };
1197 
1198  // set void
1199  template<>
1200  struct __future_base::_State_base::_Setter<void, void>
1201  {
1202  promise<void>::_Ptr_type operator()()
1203  {
1204  _State_base::_S_check(_M_promise->_M_future);
1205  return std::move(_M_promise->_M_storage);
1206  }
1207 
1208  promise<void>* _M_promise;
1209  };
1210 
1211  inline __future_base::_State_base::_Setter<void, void>
1212  __future_base::_State_base::__setter(promise<void>* __prom)
1213  {
1214  return _Setter<void, void>{ __prom };
1215  }
1216 
1217  inline void
1218  promise<void>::set_value()
1219  {
1220  auto __setter = _State::__setter(this);
1221  _M_future->_M_set_result(std::move(__setter));
1222  }
1223 
1224 
1225  template<typename _Ptr_type, typename _Res>
1226  struct __future_base::_Task_setter
1227  {
1228  _Ptr_type operator()()
1229  {
1230  __try
1231  {
1232  _M_result->_M_set(_M_fn());
1233  }
1234  __catch(...)
1235  {
1236  _M_result->_M_error = current_exception();
1237  }
1238  return std::move(_M_result);
1239  }
1240  _Ptr_type& _M_result;
1241  std::function<_Res()> _M_fn;
1242  };
1243 
1244  template<typename _Ptr_type>
1245  struct __future_base::_Task_setter<_Ptr_type, void>
1246  {
1247  _Ptr_type operator()()
1248  {
1249  __try
1250  {
1251  _M_fn();
1252  }
1253  __catch(...)
1254  {
1255  _M_result->_M_error = current_exception();
1256  }
1257  return std::move(_M_result);
1258  }
1259  _Ptr_type& _M_result;
1260  std::function<void()> _M_fn;
1261  };
1262 
1263  template<typename _Res, typename... _Args>
1264  struct __future_base::_Task_state_base<_Res(_Args...)>
1265  : __future_base::_State_base
1266  {
1267  typedef _Res _Res_type;
1268 
1269  template<typename _Alloc>
1270  _Task_state_base(const _Alloc& __a)
1271  : _M_result(_S_allocate_result<_Res>(__a))
1272  { }
1273 
1274  virtual void
1275  _M_run(_Args... __args) = 0;
1276 
1277  virtual shared_ptr<_Task_state_base>
1278  _M_reset() = 0;
1279 
1280  typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type;
1281  _Ptr_type _M_result;
1282  };
1283 
1284  template<typename _Fn, typename _Alloc, typename _Res, typename... _Args>
1285  struct __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)> final
1286  : __future_base::_Task_state_base<_Res(_Args...)>
1287  {
1288  _Task_state(_Fn&& __fn, const _Alloc& __a)
1289  : _Task_state_base<_Res(_Args...)>(__a), _M_impl(std::move(__fn), __a)
1290  { }
1291 
1292  private:
1293  virtual void
1294  _M_run(_Args... __args)
1295  {
1296  // bound arguments decay so wrap lvalue references
1297  auto __boundfn = std::__bind_simple(std::ref(_M_impl._M_fn),
1298  _S_maybe_wrap_ref(std::forward<_Args>(__args))...);
1299  auto __setter = _S_task_setter(this->_M_result, std::move(__boundfn));
1300  this->_M_set_result(std::move(__setter));
1301  }
1302 
1303  virtual shared_ptr<_Task_state_base<_Res(_Args...)>>
1304  _M_reset();
1305 
1306  template<typename _Tp>
1307  static reference_wrapper<_Tp>
1308  _S_maybe_wrap_ref(_Tp& __t)
1309  { return std::ref(__t); }
1310 
1311  template<typename _Tp>
1312  static
1313  typename enable_if<!is_lvalue_reference<_Tp>::value, _Tp>::type&&
1314  _S_maybe_wrap_ref(_Tp&& __t)
1315  { return std::forward<_Tp>(__t); }
1316 
1317  struct _Impl : _Alloc
1318  {
1319  _Impl(_Fn&& __fn, const _Alloc& __a)
1320  : _Alloc(__a), _M_fn(std::move(__fn)) { }
1321  _Fn _M_fn;
1322  } _M_impl;
1323  };
1324 
1325  template<typename _Signature, typename _Fn, typename _Alloc>
1326  static shared_ptr<__future_base::_Task_state_base<_Signature>>
1327  __create_task_state(_Fn&& __fn, const _Alloc& __a)
1328  {
1329  typedef __future_base::_Task_state<_Fn, _Alloc, _Signature> _State;
1330  return std::allocate_shared<_State>(__a, std::move(__fn), __a);
1331  }
1332 
1333  template<typename _Fn, typename _Alloc, typename _Res, typename... _Args>
1334  shared_ptr<__future_base::_Task_state_base<_Res(_Args...)>>
1335  __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)>::_M_reset()
1336  {
1337  return __create_task_state<_Res(_Args...)>(std::move(_M_impl._M_fn),
1338  static_cast<_Alloc&>(_M_impl));
1339  }
1340 
1341  template<typename _Task, typename _Fn, bool
1342  = is_same<_Task, typename decay<_Fn>::type>::value>
1343  struct __constrain_pkgdtask
1344  { typedef void __type; };
1345 
1346  template<typename _Task, typename _Fn>
1347  struct __constrain_pkgdtask<_Task, _Fn, true>
1348  { };
1349 
1350  /// packaged_task
1351  template<typename _Res, typename... _ArgTypes>
1352  class packaged_task<_Res(_ArgTypes...)>
1353  {
1354  typedef __future_base::_Task_state_base<_Res(_ArgTypes...)> _State_type;
1355  shared_ptr<_State_type> _M_state;
1356 
1357  public:
1358  // Construction and destruction
1359  packaged_task() noexcept { }
1360 
1361  // _GLIBCXX_RESOLVE_LIB_DEFECTS
1362  // 2095. missing constructors needed for uses-allocator construction
1363  template<typename _Allocator>
1364  packaged_task(allocator_arg_t, const _Allocator& __a) noexcept
1365  { }
1366 
1367  template<typename _Fn, typename = typename
1368  __constrain_pkgdtask<packaged_task, _Fn>::__type>
1369  explicit
1370  packaged_task(_Fn&& __fn)
1371  : packaged_task(allocator_arg, std::allocator<int>(), std::move(__fn))
1372  { }
1373 
1374  // _GLIBCXX_RESOLVE_LIB_DEFECTS
1375  // 2097. packaged_task constructors should be constrained
1376  template<typename _Fn, typename _Alloc, typename = typename
1377  __constrain_pkgdtask<packaged_task, _Fn>::__type>
1378  explicit
1379  packaged_task(allocator_arg_t, const _Alloc& __a, _Fn&& __fn)
1380  : _M_state(__create_task_state<_Res(_ArgTypes...)>(
1381  std::forward<_Fn>(__fn), __a))
1382  { }
1383 
1384  ~packaged_task()
1385  {
1386  if (static_cast<bool>(_M_state) && !_M_state.unique())
1387  _M_state->_M_break_promise(std::move(_M_state->_M_result));
1388  }
1389 
1390  // No copy
1391  packaged_task(const packaged_task&) = delete;
1392  packaged_task& operator=(const packaged_task&) = delete;
1393 
1394  template<typename _Allocator>
1395  packaged_task(allocator_arg_t, const _Allocator&,
1396  const packaged_task&) = delete;
1397 
1398  // Move support
1399  packaged_task(packaged_task&& __other) noexcept
1400  { this->swap(__other); }
1401 
1402  template<typename _Allocator>
1403  packaged_task(allocator_arg_t, const _Allocator&,
1404  packaged_task&& __other) noexcept
1405  { this->swap(__other); }
1406 
1407  packaged_task& operator=(packaged_task&& __other) noexcept
1408  {
1409  packaged_task(std::move(__other)).swap(*this);
1410  return *this;
1411  }
1412 
1413  void
1414  swap(packaged_task& __other) noexcept
1415  { _M_state.swap(__other._M_state); }
1416 
1417  bool
1418  valid() const noexcept
1419  { return static_cast<bool>(_M_state); }
1420 
1421  // Result retrieval
1422  future<_Res>
1423  get_future()
1424  { return future<_Res>(_M_state); }
1425 
1426  // Execution
1427  void
1428  operator()(_ArgTypes... __args)
1429  {
1430  __future_base::_State_base::_S_check(_M_state);
1431  _M_state->_M_run(std::forward<_ArgTypes>(__args)...);
1432  }
1433 
1434  void
1435  reset()
1436  {
1437  __future_base::_State_base::_S_check(_M_state);
1438  packaged_task __tmp;
1439  __tmp._M_state = _M_state;
1440  _M_state = _M_state->_M_reset();
1441  }
1442  };
1443 
1444  /// swap
1445  template<typename _Res, typename... _ArgTypes>
1446  inline void
1447  swap(packaged_task<_Res(_ArgTypes...)>& __x,
1448  packaged_task<_Res(_ArgTypes...)>& __y) noexcept
1449  { __x.swap(__y); }
1450 
1451  template<typename _Res, typename _Alloc>
1452  struct uses_allocator<packaged_task<_Res>, _Alloc>
1453  : public true_type { };
1454 
1455 
1456  template<typename _BoundFn, typename _Res>
1457  class __future_base::_Deferred_state final
1458  : public __future_base::_State_base
1459  {
1460  public:
1461  explicit
1462  _Deferred_state(_BoundFn&& __fn)
1463  : _M_result(new _Result<_Res>()), _M_fn(std::move(__fn))
1464  { }
1465 
1466  private:
1467  typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type;
1468  _Ptr_type _M_result;
1469  _BoundFn _M_fn;
1470 
1471  // Run the deferred function.
1472  virtual void
1473  _M_complete_async()
1474  {
1475  // safe to call multiple times so ignore failure
1476  _M_set_result(_S_task_setter(_M_result, _M_fn), true);
1477  }
1478 
1479  virtual bool
1480  _M_has_deferred() const { return static_cast<bool>(_M_result); }
1481  };
1482 
1483  class __future_base::_Async_state_commonV2
1484  : public __future_base::_State_base
1485  {
1486  protected:
1487  ~_Async_state_commonV2() = default;
1488 
1489  // Make waiting functions block until the thread completes, as if joined.
1490  virtual void _M_complete_async() { _M_join(); }
1491 
1492  void _M_join() { std::call_once(_M_once, &thread::join, ref(_M_thread)); }
1493 
1494  thread _M_thread;
1495  once_flag _M_once;
1496  };
1497 
1498  template<typename _BoundFn, typename _Res>
1499  class __future_base::_Async_state_impl final
1500  : public __future_base::_Async_state_commonV2
1501  {
1502  public:
1503  explicit
1504  _Async_state_impl(_BoundFn&& __fn)
1505  : _M_result(new _Result<_Res>()), _M_fn(std::move(__fn))
1506  {
1507  _M_thread = std::thread{ [this] {
1508  _M_set_result(_S_task_setter(_M_result, _M_fn));
1509  } };
1510  }
1511 
1512  ~_Async_state_impl() { _M_join(); }
1513 
1514  private:
1515  typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type;
1516  _Ptr_type _M_result;
1517  _BoundFn _M_fn;
1518  };
1519 
1520  template<typename _BoundFn>
1522  __future_base::_S_make_deferred_state(_BoundFn&& __fn)
1523  {
1524  typedef typename remove_reference<_BoundFn>::type __fn_type;
1525  typedef _Deferred_state<__fn_type> __state_type;
1526  return std::make_shared<__state_type>(std::move(__fn));
1527  }
1528 
1529  template<typename _BoundFn>
1531  __future_base::_S_make_async_state(_BoundFn&& __fn)
1532  {
1533  typedef typename remove_reference<_BoundFn>::type __fn_type;
1534  typedef _Async_state_impl<__fn_type> __state_type;
1535  return std::make_shared<__state_type>(std::move(__fn));
1536  }
1537 
1538 
1539  /// async
1540  template<typename _Fn, typename... _Args>
1541  future<typename result_of<_Fn(_Args...)>::type>
1542  async(launch __policy, _Fn&& __fn, _Args&&... __args)
1543  {
1544  typedef typename result_of<_Fn(_Args...)>::type result_type;
1546  if ((__policy & (launch::async|launch::deferred)) == launch::async)
1547  {
1548  __state = __future_base::_S_make_async_state(std::__bind_simple(
1549  std::forward<_Fn>(__fn), std::forward<_Args>(__args)...));
1550  }
1551  else
1552  {
1553  __state = __future_base::_S_make_deferred_state(std::__bind_simple(
1554  std::forward<_Fn>(__fn), std::forward<_Args>(__args)...));
1555  }
1556  return future<result_type>(__state);
1557  }
1558 
1559  /// async, potential overload
1560  template<typename _Fn, typename... _Args>
1561  inline future<typename result_of<_Fn(_Args...)>::type>
1562  async(_Fn&& __fn, _Args&&... __args)
1563  {
1564  return async(launch::async|launch::deferred, std::forward<_Fn>(__fn),
1565  std::forward<_Args>(__args)...);
1566  }
1567 
1568 #endif // _GLIBCXX_ASYNC_ABI_COMPAT
1569 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
1570  // && ATOMIC_INT_LOCK_FREE
1571 
1572  // @} group futures
1573 _GLIBCXX_END_NAMESPACE_VERSION
1574 } // namespace
1575 
1576 #endif // C++11
1577 
1578 #endif // _GLIBCXX_FUTURE
reference_wrapper< _Tp > ref(_Tp &__t) noexcept
Denotes a reference should be taken to a variable.
Definition: functional:443
thread
Definition: thread:60
error_category
Definition: system_error:66
logic_error(const string &__arg)
bitset< _Nb > operator~() const noexcept
See the no-argument flip().
Definition: bitset:1137
bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1435
future_status
Status code for futures.
Definition: future:163
bitset< _Nb > & reset() noexcept
Sets every bit to false.
Definition: bitset:1092
exception_ptr current_exception() noexcept
One of two subclasses of exception.
Definition: stdexcept:55
exception_ptr make_exception_ptr(_Ex __ex) noexcept
Obtain an exception_ptr pointing to a copy of the supplied object.
shared_ptr< _Tp > allocate_shared(const _Alloc &__a, _Args &&...__args)
Create an object that is owned by a shared_ptr.
Definition: shared_ptr.h:595
virtual const char * what() const noexcept
void call_once(once_flag &__once, _Callable &&__f, _Args &&...__args)
call_once
Definition: mutex:733
error_condition
Definition: system_error:196
integral_constant
Definition: type_traits:57
is_error_code_enum
Definition: system_error:54
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Definition: move.h:76
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
Definition: type_traits:72
future_errc
Error code for futures.
Definition: future:64
The standard allocator, as per [20.4].
Definition: allocator.h:92
A smart pointer with reference-counted copy semantics.
Definition: shared_ptr.h:93
const error_category & future_category() noexcept
Points to a statically-allocated object derived from error_category.
shared_ptr< _Tp > make_shared(_Args &&...__args)
Create an object that is owned by a shared_ptr.
Definition: shared_ptr.h:610
void rethrow_exception(exception_ptr) __attribute__((__noreturn__))
Throw the object pointed to by the exception_ptr.
void swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
Definition: functional:2534
Exception type thrown by futures.
Definition: future:94
bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1426
error_code
Definition: system_error:119
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1444
launch
Launch code for futures.
Definition: future:126