libstdc++
|
00001 // <future> -*- C++ -*- 00002 00003 // Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file include/future 00026 * This is a Standard C++ Library header. 00027 */ 00028 00029 #ifndef _GLIBCXX_FUTURE 00030 #define _GLIBCXX_FUTURE 1 00031 00032 #pragma GCC system_header 00033 00034 #ifndef __GXX_EXPERIMENTAL_CXX0X__ 00035 # include <bits/c++0x_warning.h> 00036 #else 00037 00038 #include <functional> 00039 #include <memory> 00040 #include <mutex> 00041 #include <thread> 00042 #include <condition_variable> 00043 #include <system_error> 00044 #include <exception> 00045 #include <atomic> 00046 #include <bits/functexcept.h> 00047 00048 namespace std _GLIBCXX_VISIBILITY(default) 00049 { 00050 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00051 00052 /** 00053 * @defgroup futures Futures 00054 * @ingroup concurrency 00055 * 00056 * Classes for futures support. 00057 * @{ 00058 */ 00059 00060 /// Error code for futures 00061 enum class future_errc 00062 { 00063 future_already_retrieved = 1, 00064 promise_already_satisfied, 00065 no_state, 00066 broken_promise 00067 }; 00068 00069 /// Specialization. 00070 template<> 00071 struct is_error_code_enum<future_errc> : public true_type { }; 00072 00073 /// Points to a statically-allocated object derived from error_category. 00074 const error_category& 00075 future_category() noexcept; 00076 00077 /// Overload for make_error_code. 00078 inline error_code 00079 make_error_code(future_errc __errc) noexcept 00080 { return error_code(static_cast<int>(__errc), future_category()); } 00081 00082 /// Overload for make_error_condition. 00083 inline error_condition 00084 make_error_condition(future_errc __errc) noexcept 00085 { return error_condition(static_cast<int>(__errc), future_category()); } 00086 00087 /** 00088 * @brief Exception type thrown by futures. 00089 * @ingroup exceptions 00090 */ 00091 class future_error : public logic_error 00092 { 00093 error_code _M_code; 00094 00095 public: 00096 explicit future_error(error_code __ec) 00097 : logic_error("std::future_error"), _M_code(__ec) 00098 { } 00099 00100 virtual ~future_error() noexcept; 00101 00102 virtual const char* 00103 what() const noexcept; 00104 00105 const error_code& 00106 code() const noexcept { return _M_code; } 00107 }; 00108 00109 // Forward declarations. 00110 template<typename _Res> 00111 class future; 00112 00113 template<typename _Res> 00114 class shared_future; 00115 00116 template<typename _Res> 00117 class atomic_future; 00118 00119 template<typename _Signature> 00120 class packaged_task; 00121 00122 template<typename _Res> 00123 class promise; 00124 00125 /// Launch code for futures 00126 enum class launch 00127 { 00128 async = 1, 00129 deferred = 2 00130 }; 00131 00132 constexpr launch operator&(launch __x, launch __y) 00133 { 00134 return static_cast<launch>( 00135 static_cast<int>(__x) & static_cast<int>(__y)); 00136 } 00137 00138 constexpr launch operator|(launch __x, launch __y) 00139 { 00140 return static_cast<launch>( 00141 static_cast<int>(__x) | static_cast<int>(__y)); 00142 } 00143 00144 constexpr launch operator^(launch __x, launch __y) 00145 { 00146 return static_cast<launch>( 00147 static_cast<int>(__x) ^ static_cast<int>(__y)); 00148 } 00149 00150 constexpr launch operator~(launch __x) 00151 { return static_cast<launch>(~static_cast<int>(__x)); } 00152 00153 inline launch& operator&=(launch& __x, launch __y) 00154 { return __x = __x & __y; } 00155 00156 inline launch& operator|=(launch& __x, launch __y) 00157 { return __x = __x | __y; } 00158 00159 inline launch& operator^=(launch& __x, launch __y) 00160 { return __x = __x ^ __y; } 00161 00162 /// Status code for futures 00163 enum class future_status 00164 { 00165 ready, 00166 timeout, 00167 deferred 00168 }; 00169 00170 template<typename _Fn, typename... _Args> 00171 future<typename result_of<_Fn(_Args...)>::type> 00172 async(launch __policy, _Fn&& __fn, _Args&&... __args); 00173 00174 template<typename _FnCheck, typename _Fn, typename... _Args> 00175 struct __async_sfinae_helper 00176 { 00177 typedef future<typename result_of<_Fn(_Args...)>::type> type; 00178 }; 00179 00180 template<typename _Fn, typename... _Args> 00181 struct __async_sfinae_helper<launch, _Fn, _Args...> 00182 { }; 00183 00184 template<typename _Fn, typename... _Args> 00185 typename 00186 __async_sfinae_helper<typename decay<_Fn>::type, _Fn, _Args...>::type 00187 async(_Fn&& __fn, _Args&&... __args); 00188 00189 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \ 00190 && (ATOMIC_INT_LOCK_FREE > 1) 00191 00192 /// Base class and enclosing scope. 00193 struct __future_base 00194 { 00195 /// Base class for results. 00196 struct _Result_base 00197 { 00198 exception_ptr _M_error; 00199 00200 _Result_base(const _Result_base&) = delete; 00201 _Result_base& operator=(const _Result_base&) = delete; 00202 00203 // _M_destroy() allows derived classes to control deallocation 00204 virtual void _M_destroy() = 0; 00205 00206 struct _Deleter 00207 { 00208 void operator()(_Result_base* __fr) const { __fr->_M_destroy(); } 00209 }; 00210 00211 protected: 00212 _Result_base(); 00213 virtual ~_Result_base(); 00214 }; 00215 00216 /// Result. 00217 template<typename _Res> 00218 struct _Result : _Result_base 00219 { 00220 private: 00221 typedef alignment_of<_Res> __a_of; 00222 typedef aligned_storage<sizeof(_Res), __a_of::value> __align_storage; 00223 typedef typename __align_storage::type __align_type; 00224 00225 __align_type _M_storage; 00226 bool _M_initialized; 00227 00228 public: 00229 _Result() noexcept : _M_initialized() { } 00230 00231 ~_Result() 00232 { 00233 if (_M_initialized) 00234 _M_value().~_Res(); 00235 } 00236 00237 // Return lvalue, future will add const or rvalue-reference 00238 _Res& 00239 _M_value() noexcept { return *static_cast<_Res*>(_M_addr()); } 00240 00241 void 00242 _M_set(const _Res& __res) 00243 { 00244 ::new (_M_addr()) _Res(__res); 00245 _M_initialized = true; 00246 } 00247 00248 void 00249 _M_set(_Res&& __res) 00250 { 00251 ::new (_M_addr()) _Res(std::move(__res)); 00252 _M_initialized = true; 00253 } 00254 00255 private: 00256 void _M_destroy() { delete this; } 00257 00258 void* _M_addr() noexcept { return static_cast<void*>(&_M_storage); } 00259 }; 00260 00261 /// A unique_ptr based on the instantiating type. 00262 template<typename _Res> 00263 using _Ptr = unique_ptr<_Res, _Result_base::_Deleter>; 00264 00265 /// Result_alloc. 00266 template<typename _Res, typename _Alloc> 00267 struct _Result_alloc final : _Result<_Res>, _Alloc 00268 { 00269 typedef typename allocator_traits<_Alloc>::template 00270 rebind_alloc<_Result_alloc> __allocator_type; 00271 00272 explicit 00273 _Result_alloc(const _Alloc& __a) : _Result<_Res>(), _Alloc(__a) 00274 { } 00275 00276 private: 00277 void _M_destroy() 00278 { 00279 typedef allocator_traits<__allocator_type> __traits; 00280 __allocator_type __a(*this); 00281 __traits::destroy(__a, this); 00282 __traits::deallocate(__a, this, 1); 00283 } 00284 }; 00285 00286 template<typename _Res, typename _Allocator> 00287 static _Ptr<_Result_alloc<_Res, _Allocator>> 00288 _S_allocate_result(const _Allocator& __a) 00289 { 00290 typedef _Result_alloc<_Res, _Allocator> __result_type; 00291 typedef allocator_traits<typename __result_type::__allocator_type> 00292 __traits; 00293 typename __traits::allocator_type __a2(__a); 00294 __result_type* __p = __traits::allocate(__a2, 1); 00295 __try 00296 { 00297 __traits::construct(__a2, __p, __a); 00298 } 00299 __catch(...) 00300 { 00301 __traits::deallocate(__a2, __p, 1); 00302 __throw_exception_again; 00303 } 00304 return _Ptr<__result_type>(__p); 00305 } 00306 00307 00308 /// Base class for state between a promise and one or more 00309 /// associated futures. 00310 class _State_base 00311 { 00312 typedef _Ptr<_Result_base> _Ptr_type; 00313 00314 _Ptr_type _M_result; 00315 mutex _M_mutex; 00316 condition_variable _M_cond; 00317 atomic_flag _M_retrieved; 00318 once_flag _M_once; 00319 00320 public: 00321 _State_base() noexcept : _M_result(), _M_retrieved(ATOMIC_FLAG_INIT) { } 00322 _State_base(const _State_base&) = delete; 00323 _State_base& operator=(const _State_base&) = delete; 00324 virtual ~_State_base(); 00325 00326 _Result_base& 00327 wait() 00328 { 00329 _M_run_deferred(); 00330 unique_lock<mutex> __lock(_M_mutex); 00331 _M_cond.wait(__lock, [&] { return _M_ready(); }); 00332 return *_M_result; 00333 } 00334 00335 template<typename _Rep, typename _Period> 00336 future_status 00337 wait_for(const chrono::duration<_Rep, _Period>& __rel) 00338 { 00339 unique_lock<mutex> __lock(_M_mutex); 00340 if (_M_cond.wait_for(__lock, __rel, [&] { return _M_ready(); })) 00341 return future_status::ready; 00342 return future_status::timeout; 00343 } 00344 00345 template<typename _Clock, typename _Duration> 00346 future_status 00347 wait_until(const chrono::time_point<_Clock, _Duration>& __abs) 00348 { 00349 unique_lock<mutex> __lock(_M_mutex); 00350 if (_M_cond.wait_until(__lock, __abs, [&] { return _M_ready(); })) 00351 return future_status::ready; 00352 return future_status::timeout; 00353 } 00354 00355 void 00356 _M_set_result(function<_Ptr_type()> __res, bool __ignore_failure = false) 00357 { 00358 bool __set = __ignore_failure; 00359 // all calls to this function are serialized, 00360 // side-effects of invoking __res only happen once 00361 call_once(_M_once, &_State_base::_M_do_set, this, ref(__res), 00362 ref(__set)); 00363 if (!__set) 00364 __throw_future_error(int(future_errc::promise_already_satisfied)); 00365 } 00366 00367 void 00368 _M_break_promise(_Ptr_type __res) 00369 { 00370 if (static_cast<bool>(__res)) 00371 { 00372 error_code __ec(make_error_code(future_errc::broken_promise)); 00373 __res->_M_error = copy_exception(future_error(__ec)); 00374 { 00375 lock_guard<mutex> __lock(_M_mutex); 00376 _M_result.swap(__res); 00377 } 00378 _M_cond.notify_all(); 00379 } 00380 } 00381 00382 // Called when this object is passed to a future. 00383 void 00384 _M_set_retrieved_flag() 00385 { 00386 if (_M_retrieved.test_and_set()) 00387 __throw_future_error(int(future_errc::future_already_retrieved)); 00388 } 00389 00390 template<typename _Res, typename _Arg> 00391 struct _Setter; 00392 00393 // set lvalues 00394 template<typename _Res, typename _Arg> 00395 struct _Setter<_Res, _Arg&> 00396 { 00397 // check this is only used by promise<R>::set_value(const R&) 00398 // or promise<R>::set_value(R&) 00399 static_assert(is_same<_Res, _Arg&>::value // promise<R&> 00400 || is_same<const _Res, _Arg>::value, // promise<R> 00401 "Invalid specialisation"); 00402 00403 typename promise<_Res>::_Ptr_type operator()() 00404 { 00405 _State_base::_S_check(_M_promise->_M_future); 00406 _M_promise->_M_storage->_M_set(_M_arg); 00407 return std::move(_M_promise->_M_storage); 00408 } 00409 promise<_Res>* _M_promise; 00410 _Arg& _M_arg; 00411 }; 00412 00413 // set rvalues 00414 template<typename _Res> 00415 struct _Setter<_Res, _Res&&> 00416 { 00417 typename promise<_Res>::_Ptr_type operator()() 00418 { 00419 _State_base::_S_check(_M_promise->_M_future); 00420 _M_promise->_M_storage->_M_set(std::move(_M_arg)); 00421 return std::move(_M_promise->_M_storage); 00422 } 00423 promise<_Res>* _M_promise; 00424 _Res& _M_arg; 00425 }; 00426 00427 struct __exception_ptr_tag { }; 00428 00429 // set exceptions 00430 template<typename _Res> 00431 struct _Setter<_Res, __exception_ptr_tag> 00432 { 00433 typename promise<_Res>::_Ptr_type operator()() 00434 { 00435 _State_base::_S_check(_M_promise->_M_future); 00436 _M_promise->_M_storage->_M_error = _M_ex; 00437 return std::move(_M_promise->_M_storage); 00438 } 00439 00440 promise<_Res>* _M_promise; 00441 exception_ptr& _M_ex; 00442 }; 00443 00444 template<typename _Res, typename _Arg> 00445 static _Setter<_Res, _Arg&&> 00446 __setter(promise<_Res>* __prom, _Arg&& __arg) 00447 { 00448 return _Setter<_Res, _Arg&&>{ __prom, __arg }; 00449 } 00450 00451 template<typename _Res> 00452 static _Setter<_Res, __exception_ptr_tag> 00453 __setter(exception_ptr& __ex, promise<_Res>* __prom) 00454 { 00455 return _Setter<_Res, __exception_ptr_tag>{ __prom, __ex }; 00456 } 00457 00458 static _Setter<void, void> 00459 __setter(promise<void>* __prom); 00460 00461 template<typename _Tp> 00462 static bool 00463 _S_check(const shared_ptr<_Tp>& __p) 00464 { 00465 if (!static_cast<bool>(__p)) 00466 __throw_future_error((int)future_errc::no_state); 00467 } 00468 00469 private: 00470 void 00471 _M_do_set(function<_Ptr_type()>& __f, bool& __set) 00472 { 00473 _Ptr_type __res = __f(); 00474 { 00475 lock_guard<mutex> __lock(_M_mutex); 00476 _M_result.swap(__res); 00477 } 00478 _M_cond.notify_all(); 00479 __set = true; 00480 } 00481 00482 bool _M_ready() const noexcept { return static_cast<bool>(_M_result); } 00483 00484 // Misnamed: waits for completion of async function. 00485 virtual void _M_run_deferred() { } 00486 }; 00487 00488 template<typename _BoundFn, typename = typename _BoundFn::result_type> 00489 class _Deferred_state; 00490 00491 class _Async_state_common; 00492 00493 template<typename _BoundFn, typename = typename _BoundFn::result_type> 00494 class _Async_state_impl; 00495 00496 template<typename _Signature> 00497 class _Task_state; 00498 00499 template<typename _BoundFn> 00500 static std::shared_ptr<_State_base> 00501 _S_make_deferred_state(_BoundFn&& __fn); 00502 00503 template<typename _BoundFn> 00504 static std::shared_ptr<_State_base> 00505 _S_make_async_state(_BoundFn&& __fn); 00506 00507 template<typename _Res_ptr, typename _Res> 00508 struct _Task_setter; 00509 00510 template<typename _Res_ptr, typename _BoundFn> 00511 class _Task_setter_helper 00512 { 00513 typedef typename remove_reference<_BoundFn>::type::result_type __res; 00514 public: 00515 typedef _Task_setter<_Res_ptr, __res> __type; 00516 }; 00517 00518 template<typename _Res_ptr, typename _BoundFn> 00519 static typename _Task_setter_helper<_Res_ptr, _BoundFn>::__type 00520 _S_task_setter(_Res_ptr& __ptr, _BoundFn&& __call) 00521 { 00522 typedef _Task_setter_helper<_Res_ptr, _BoundFn> __helper_type; 00523 typedef typename __helper_type::__type _Setter; 00524 return _Setter{ __ptr, std::ref(__call) }; 00525 } 00526 }; 00527 00528 /// Partial specialization for reference types. 00529 template<typename _Res> 00530 struct __future_base::_Result<_Res&> : __future_base::_Result_base 00531 { 00532 _Result() noexcept : _M_value_ptr() { } 00533 00534 void _M_set(_Res& __res) noexcept { _M_value_ptr = &__res; } 00535 00536 _Res& _M_get() noexcept { return *_M_value_ptr; } 00537 00538 private: 00539 _Res* _M_value_ptr; 00540 00541 void _M_destroy() { delete this; } 00542 }; 00543 00544 /// Explicit specialization for void. 00545 template<> 00546 struct __future_base::_Result<void> : __future_base::_Result_base 00547 { 00548 private: 00549 void _M_destroy() { delete this; } 00550 }; 00551 00552 00553 /// Common implementation for future and shared_future. 00554 template<typename _Res> 00555 class __basic_future : public __future_base 00556 { 00557 protected: 00558 typedef shared_ptr<_State_base> __state_type; 00559 typedef __future_base::_Result<_Res>& __result_type; 00560 00561 private: 00562 __state_type _M_state; 00563 00564 public: 00565 // Disable copying. 00566 __basic_future(const __basic_future&) = delete; 00567 __basic_future& operator=(const __basic_future&) = delete; 00568 00569 bool 00570 valid() const noexcept { return static_cast<bool>(_M_state); } 00571 00572 void 00573 wait() const 00574 { 00575 _State_base::_S_check(_M_state); 00576 _M_state->wait(); 00577 } 00578 00579 template<typename _Rep, typename _Period> 00580 future_status 00581 wait_for(const chrono::duration<_Rep, _Period>& __rel) const 00582 { 00583 _State_base::_S_check(_M_state); 00584 return _M_state->wait_for(__rel); 00585 } 00586 00587 template<typename _Clock, typename _Duration> 00588 future_status 00589 wait_until(const chrono::time_point<_Clock, _Duration>& __abs) const 00590 { 00591 _State_base::_S_check(_M_state); 00592 return _M_state->wait_until(__abs); 00593 } 00594 00595 protected: 00596 /// Wait for the state to be ready and rethrow any stored exception 00597 __result_type 00598 _M_get_result() 00599 { 00600 _State_base::_S_check(_M_state); 00601 _Result_base& __res = _M_state->wait(); 00602 if (!(__res._M_error == 0)) 00603 rethrow_exception(__res._M_error); 00604 return static_cast<__result_type>(__res); 00605 } 00606 00607 void _M_swap(__basic_future& __that) noexcept 00608 { 00609 _M_state.swap(__that._M_state); 00610 } 00611 00612 // Construction of a future by promise::get_future() 00613 explicit 00614 __basic_future(const __state_type& __state) : _M_state(__state) 00615 { 00616 _State_base::_S_check(_M_state); 00617 _M_state->_M_set_retrieved_flag(); 00618 } 00619 00620 // Copy construction from a shared_future 00621 explicit 00622 __basic_future(const shared_future<_Res>&) noexcept; 00623 00624 // Move construction from a shared_future 00625 explicit 00626 __basic_future(shared_future<_Res>&&) noexcept; 00627 00628 // Move construction from a future 00629 explicit 00630 __basic_future(future<_Res>&&) noexcept; 00631 00632 constexpr __basic_future() noexcept : _M_state() { } 00633 00634 struct _Reset 00635 { 00636 explicit _Reset(__basic_future& __fut) noexcept : _M_fut(__fut) { } 00637 ~_Reset() { _M_fut._M_state.reset(); } 00638 __basic_future& _M_fut; 00639 }; 00640 }; 00641 00642 00643 /// Primary template for future. 00644 template<typename _Res> 00645 class future : public __basic_future<_Res> 00646 { 00647 friend class promise<_Res>; 00648 template<typename> friend class packaged_task; 00649 template<typename _Fn, typename... _Args> 00650 friend future<typename result_of<_Fn(_Args...)>::type> 00651 async(launch, _Fn&&, _Args&&...); 00652 00653 typedef __basic_future<_Res> _Base_type; 00654 typedef typename _Base_type::__state_type __state_type; 00655 00656 explicit 00657 future(const __state_type& __state) : _Base_type(__state) { } 00658 00659 public: 00660 constexpr future() noexcept : _Base_type() { } 00661 00662 /// Move constructor 00663 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { } 00664 00665 // Disable copying 00666 future(const future&) = delete; 00667 future& operator=(const future&) = delete; 00668 00669 future& operator=(future&& __fut) noexcept 00670 { 00671 future(std::move(__fut))._M_swap(*this); 00672 return *this; 00673 } 00674 00675 /// Retrieving the value 00676 _Res 00677 get() 00678 { 00679 typename _Base_type::_Reset __reset(*this); 00680 return std::move(this->_M_get_result()._M_value()); 00681 } 00682 00683 shared_future<_Res> share(); 00684 }; 00685 00686 /// Partial specialization for future<R&> 00687 template<typename _Res> 00688 class future<_Res&> : public __basic_future<_Res&> 00689 { 00690 friend class promise<_Res&>; 00691 template<typename> friend class packaged_task; 00692 template<typename _Fn, typename... _Args> 00693 friend future<typename result_of<_Fn(_Args...)>::type> 00694 async(launch, _Fn&&, _Args&&...); 00695 00696 typedef __basic_future<_Res&> _Base_type; 00697 typedef typename _Base_type::__state_type __state_type; 00698 00699 explicit 00700 future(const __state_type& __state) : _Base_type(__state) { } 00701 00702 public: 00703 constexpr future() noexcept : _Base_type() { } 00704 00705 /// Move constructor 00706 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { } 00707 00708 // Disable copying 00709 future(const future&) = delete; 00710 future& operator=(const future&) = delete; 00711 00712 future& operator=(future&& __fut) noexcept 00713 { 00714 future(std::move(__fut))._M_swap(*this); 00715 return *this; 00716 } 00717 00718 /// Retrieving the value 00719 _Res& 00720 get() 00721 { 00722 typename _Base_type::_Reset __reset(*this); 00723 return this->_M_get_result()._M_get(); 00724 } 00725 00726 shared_future<_Res&> share(); 00727 }; 00728 00729 /// Explicit specialization for future<void> 00730 template<> 00731 class future<void> : public __basic_future<void> 00732 { 00733 friend class promise<void>; 00734 template<typename> friend class packaged_task; 00735 template<typename _Fn, typename... _Args> 00736 friend future<typename result_of<_Fn(_Args...)>::type> 00737 async(launch, _Fn&&, _Args&&...); 00738 00739 typedef __basic_future<void> _Base_type; 00740 typedef typename _Base_type::__state_type __state_type; 00741 00742 explicit 00743 future(const __state_type& __state) : _Base_type(__state) { } 00744 00745 public: 00746 constexpr future() noexcept : _Base_type() { } 00747 00748 /// Move constructor 00749 future(future&& __uf) noexcept : _Base_type(std::move(__uf)) { } 00750 00751 // Disable copying 00752 future(const future&) = delete; 00753 future& operator=(const future&) = delete; 00754 00755 future& operator=(future&& __fut) noexcept 00756 { 00757 future(std::move(__fut))._M_swap(*this); 00758 return *this; 00759 } 00760 00761 /// Retrieving the value 00762 void 00763 get() 00764 { 00765 typename _Base_type::_Reset __reset(*this); 00766 this->_M_get_result(); 00767 } 00768 00769 shared_future<void> share(); 00770 }; 00771 00772 00773 /// Primary template for shared_future. 00774 template<typename _Res> 00775 class shared_future : public __basic_future<_Res> 00776 { 00777 typedef __basic_future<_Res> _Base_type; 00778 00779 public: 00780 constexpr shared_future() noexcept : _Base_type() { } 00781 00782 /// Copy constructor 00783 shared_future(const shared_future& __sf) : _Base_type(__sf) { } 00784 00785 /// Construct from a future rvalue 00786 shared_future(future<_Res>&& __uf) noexcept 00787 : _Base_type(std::move(__uf)) 00788 { } 00789 00790 /// Construct from a shared_future rvalue 00791 shared_future(shared_future&& __sf) noexcept 00792 : _Base_type(std::move(__sf)) 00793 { } 00794 00795 shared_future& operator=(const shared_future& __sf) 00796 { 00797 shared_future(__sf)._M_swap(*this); 00798 return *this; 00799 } 00800 00801 shared_future& operator=(shared_future&& __sf) noexcept 00802 { 00803 shared_future(std::move(__sf))._M_swap(*this); 00804 return *this; 00805 } 00806 00807 /// Retrieving the value 00808 const _Res& 00809 get() 00810 { 00811 typename _Base_type::__result_type __r = this->_M_get_result(); 00812 _Res& __rs(__r._M_value()); 00813 return __rs; 00814 } 00815 }; 00816 00817 /// Partial specialization for shared_future<R&> 00818 template<typename _Res> 00819 class shared_future<_Res&> : public __basic_future<_Res&> 00820 { 00821 typedef __basic_future<_Res&> _Base_type; 00822 00823 public: 00824 constexpr shared_future() noexcept : _Base_type() { } 00825 00826 /// Copy constructor 00827 shared_future(const shared_future& __sf) : _Base_type(__sf) { } 00828 00829 /// Construct from a future rvalue 00830 shared_future(future<_Res&>&& __uf) noexcept 00831 : _Base_type(std::move(__uf)) 00832 { } 00833 00834 /// Construct from a shared_future rvalue 00835 shared_future(shared_future&& __sf) noexcept 00836 : _Base_type(std::move(__sf)) 00837 { } 00838 00839 shared_future& operator=(const shared_future& __sf) 00840 { 00841 shared_future(__sf)._M_swap(*this); 00842 return *this; 00843 } 00844 00845 shared_future& operator=(shared_future&& __sf) noexcept 00846 { 00847 shared_future(std::move(__sf))._M_swap(*this); 00848 return *this; 00849 } 00850 00851 /// Retrieving the value 00852 _Res& 00853 get() { return this->_M_get_result()._M_get(); } 00854 }; 00855 00856 /// Explicit specialization for shared_future<void> 00857 template<> 00858 class shared_future<void> : public __basic_future<void> 00859 { 00860 typedef __basic_future<void> _Base_type; 00861 00862 public: 00863 constexpr shared_future() noexcept : _Base_type() { } 00864 00865 /// Copy constructor 00866 shared_future(const shared_future& __sf) : _Base_type(__sf) { } 00867 00868 /// Construct from a future rvalue 00869 shared_future(future<void>&& __uf) noexcept 00870 : _Base_type(std::move(__uf)) 00871 { } 00872 00873 /// Construct from a shared_future rvalue 00874 shared_future(shared_future&& __sf) noexcept 00875 : _Base_type(std::move(__sf)) 00876 { } 00877 00878 shared_future& operator=(const shared_future& __sf) 00879 { 00880 shared_future(__sf)._M_swap(*this); 00881 return *this; 00882 } 00883 00884 shared_future& operator=(shared_future&& __sf) noexcept 00885 { 00886 shared_future(std::move(__sf))._M_swap(*this); 00887 return *this; 00888 } 00889 00890 // Retrieving the value 00891 void 00892 get() { this->_M_get_result(); } 00893 }; 00894 00895 // Now we can define the protected __basic_future constructors. 00896 template<typename _Res> 00897 inline __basic_future<_Res>:: 00898 __basic_future(const shared_future<_Res>& __sf) noexcept 00899 : _M_state(__sf._M_state) 00900 { } 00901 00902 template<typename _Res> 00903 inline __basic_future<_Res>:: 00904 __basic_future(shared_future<_Res>&& __sf) noexcept 00905 : _M_state(std::move(__sf._M_state)) 00906 { } 00907 00908 template<typename _Res> 00909 inline __basic_future<_Res>:: 00910 __basic_future(future<_Res>&& __uf) noexcept 00911 : _M_state(std::move(__uf._M_state)) 00912 { } 00913 00914 template<typename _Res> 00915 inline shared_future<_Res> 00916 future<_Res>::share() 00917 { return shared_future<_Res>(std::move(*this)); } 00918 00919 template<typename _Res> 00920 inline shared_future<_Res&> 00921 future<_Res&>::share() 00922 { return shared_future<_Res&>(std::move(*this)); } 00923 00924 inline shared_future<void> 00925 future<void>::share() 00926 { return shared_future<void>(std::move(*this)); } 00927 00928 /// Primary template for promise 00929 template<typename _Res> 00930 class promise 00931 { 00932 typedef __future_base::_State_base _State; 00933 typedef __future_base::_Result<_Res> _Res_type; 00934 typedef __future_base::_Ptr<_Res_type> _Ptr_type; 00935 template<typename, typename> friend class _State::_Setter; 00936 00937 shared_ptr<_State> _M_future; 00938 _Ptr_type _M_storage; 00939 00940 public: 00941 promise() 00942 : _M_future(std::make_shared<_State>()), 00943 _M_storage(new _Res_type()) 00944 { } 00945 00946 promise(promise&& __rhs) noexcept 00947 : _M_future(std::move(__rhs._M_future)), 00948 _M_storage(std::move(__rhs._M_storage)) 00949 { } 00950 00951 template<typename _Allocator> 00952 promise(allocator_arg_t, const _Allocator& __a) 00953 : _M_future(std::allocate_shared<_State>(__a)), 00954 _M_storage(__future_base::_S_allocate_result<_Res>(__a)) 00955 { } 00956 00957 template<typename _Allocator> 00958 promise(allocator_arg_t, const _Allocator&, promise&& __rhs) 00959 : _M_future(std::move(__rhs._M_future)), 00960 _M_storage(std::move(__rhs._M_storage)) 00961 { } 00962 00963 promise(const promise&) = delete; 00964 00965 ~promise() 00966 { 00967 if (static_cast<bool>(_M_future) && !_M_future.unique()) 00968 _M_future->_M_break_promise(std::move(_M_storage)); 00969 } 00970 00971 // Assignment 00972 promise& 00973 operator=(promise&& __rhs) noexcept 00974 { 00975 promise(std::move(__rhs)).swap(*this); 00976 return *this; 00977 } 00978 00979 promise& operator=(const promise&) = delete; 00980 00981 void 00982 swap(promise& __rhs) noexcept 00983 { 00984 _M_future.swap(__rhs._M_future); 00985 _M_storage.swap(__rhs._M_storage); 00986 } 00987 00988 // Retrieving the result 00989 future<_Res> 00990 get_future() 00991 { return future<_Res>(_M_future); } 00992 00993 // Setting the result 00994 void 00995 set_value(const _Res& __r) 00996 { 00997 auto __setter = _State::__setter(this, __r); 00998 _M_future->_M_set_result(std::move(__setter)); 00999 } 01000 01001 void 01002 set_value(_Res&& __r) 01003 { 01004 auto __setter = _State::__setter(this, std::move(__r)); 01005 _M_future->_M_set_result(std::move(__setter)); 01006 } 01007 01008 void 01009 set_exception(exception_ptr __p) 01010 { 01011 auto __setter = _State::__setter(__p, this); 01012 _M_future->_M_set_result(std::move(__setter)); 01013 } 01014 }; 01015 01016 template<typename _Res> 01017 inline void 01018 swap(promise<_Res>& __x, promise<_Res>& __y) noexcept 01019 { __x.swap(__y); } 01020 01021 template<typename _Res, typename _Alloc> 01022 struct uses_allocator<promise<_Res>, _Alloc> 01023 : public true_type { }; 01024 01025 01026 /// Partial specialization for promise<R&> 01027 template<typename _Res> 01028 class promise<_Res&> 01029 { 01030 typedef __future_base::_State_base _State; 01031 typedef __future_base::_Result<_Res&> _Res_type; 01032 typedef __future_base::_Ptr<_Res_type> _Ptr_type; 01033 template<typename, typename> friend class _State::_Setter; 01034 01035 shared_ptr<_State> _M_future; 01036 _Ptr_type _M_storage; 01037 01038 public: 01039 promise() 01040 : _M_future(std::make_shared<_State>()), 01041 _M_storage(new _Res_type()) 01042 { } 01043 01044 promise(promise&& __rhs) noexcept 01045 : _M_future(std::move(__rhs._M_future)), 01046 _M_storage(std::move(__rhs._M_storage)) 01047 { } 01048 01049 template<typename _Allocator> 01050 promise(allocator_arg_t, const _Allocator& __a) 01051 : _M_future(std::allocate_shared<_State>(__a)), 01052 _M_storage(__future_base::_S_allocate_result<_Res&>(__a)) 01053 { } 01054 01055 template<typename _Allocator> 01056 promise(allocator_arg_t, const _Allocator&, promise&& __rhs) 01057 : _M_future(std::move(__rhs._M_future)), 01058 _M_storage(std::move(__rhs._M_storage)) 01059 { } 01060 01061 promise(const promise&) = delete; 01062 01063 ~promise() 01064 { 01065 if (static_cast<bool>(_M_future) && !_M_future.unique()) 01066 _M_future->_M_break_promise(std::move(_M_storage)); 01067 } 01068 01069 // Assignment 01070 promise& 01071 operator=(promise&& __rhs) noexcept 01072 { 01073 promise(std::move(__rhs)).swap(*this); 01074 return *this; 01075 } 01076 01077 promise& operator=(const promise&) = delete; 01078 01079 void 01080 swap(promise& __rhs) noexcept 01081 { 01082 _M_future.swap(__rhs._M_future); 01083 _M_storage.swap(__rhs._M_storage); 01084 } 01085 01086 // Retrieving the result 01087 future<_Res&> 01088 get_future() 01089 { return future<_Res&>(_M_future); } 01090 01091 // Setting the result 01092 void 01093 set_value(_Res& __r) 01094 { 01095 auto __setter = _State::__setter(this, __r); 01096 _M_future->_M_set_result(std::move(__setter)); 01097 } 01098 01099 void 01100 set_exception(exception_ptr __p) 01101 { 01102 auto __setter = _State::__setter(__p, this); 01103 _M_future->_M_set_result(std::move(__setter)); 01104 } 01105 }; 01106 01107 /// Explicit specialization for promise<void> 01108 template<> 01109 class promise<void> 01110 { 01111 typedef __future_base::_State_base _State; 01112 typedef __future_base::_Result<void> _Res_type; 01113 typedef __future_base::_Ptr<_Res_type> _Ptr_type; 01114 template<typename, typename> friend class _State::_Setter; 01115 01116 shared_ptr<_State> _M_future; 01117 _Ptr_type _M_storage; 01118 01119 public: 01120 promise() 01121 : _M_future(std::make_shared<_State>()), 01122 _M_storage(new _Res_type()) 01123 { } 01124 01125 promise(promise&& __rhs) noexcept 01126 : _M_future(std::move(__rhs._M_future)), 01127 _M_storage(std::move(__rhs._M_storage)) 01128 { } 01129 01130 template<typename _Allocator> 01131 promise(allocator_arg_t, const _Allocator& __a) 01132 : _M_future(std::allocate_shared<_State>(__a)), 01133 _M_storage(__future_base::_S_allocate_result<void>(__a)) 01134 { } 01135 01136 template<typename _Allocator> 01137 promise(allocator_arg_t, const _Allocator&, promise&& __rhs) 01138 : _M_future(std::move(__rhs._M_future)), 01139 _M_storage(std::move(__rhs._M_storage)) 01140 { } 01141 01142 promise(const promise&) = delete; 01143 01144 ~promise() 01145 { 01146 if (static_cast<bool>(_M_future) && !_M_future.unique()) 01147 _M_future->_M_break_promise(std::move(_M_storage)); 01148 } 01149 01150 // Assignment 01151 promise& 01152 operator=(promise&& __rhs) noexcept 01153 { 01154 promise(std::move(__rhs)).swap(*this); 01155 return *this; 01156 } 01157 01158 promise& operator=(const promise&) = delete; 01159 01160 void 01161 swap(promise& __rhs) noexcept 01162 { 01163 _M_future.swap(__rhs._M_future); 01164 _M_storage.swap(__rhs._M_storage); 01165 } 01166 01167 // Retrieving the result 01168 future<void> 01169 get_future() 01170 { return future<void>(_M_future); } 01171 01172 // Setting the result 01173 void set_value(); 01174 01175 void 01176 set_exception(exception_ptr __p) 01177 { 01178 auto __setter = _State::__setter(__p, this); 01179 _M_future->_M_set_result(std::move(__setter)); 01180 } 01181 }; 01182 01183 // set void 01184 template<> 01185 struct __future_base::_State_base::_Setter<void, void> 01186 { 01187 promise<void>::_Ptr_type operator()() 01188 { 01189 _State_base::_S_check(_M_promise->_M_future); 01190 return std::move(_M_promise->_M_storage); 01191 } 01192 01193 promise<void>* _M_promise; 01194 }; 01195 01196 inline __future_base::_State_base::_Setter<void, void> 01197 __future_base::_State_base::__setter(promise<void>* __prom) 01198 { 01199 return _Setter<void, void>{ __prom }; 01200 } 01201 01202 inline void 01203 promise<void>::set_value() 01204 { 01205 auto __setter = _State::__setter(this); 01206 _M_future->_M_set_result(std::move(__setter)); 01207 } 01208 01209 01210 template<typename _Ptr_type, typename _Res> 01211 struct __future_base::_Task_setter 01212 { 01213 _Ptr_type operator()() 01214 { 01215 __try 01216 { 01217 _M_result->_M_set(_M_fn()); 01218 } 01219 __catch(...) 01220 { 01221 _M_result->_M_error = current_exception(); 01222 } 01223 return std::move(_M_result); 01224 } 01225 _Ptr_type& _M_result; 01226 std::function<_Res()> _M_fn; 01227 }; 01228 01229 template<typename _Ptr_type> 01230 struct __future_base::_Task_setter<_Ptr_type, void> 01231 { 01232 _Ptr_type operator()() 01233 { 01234 __try 01235 { 01236 _M_fn(); 01237 } 01238 __catch(...) 01239 { 01240 _M_result->_M_error = current_exception(); 01241 } 01242 return std::move(_M_result); 01243 } 01244 _Ptr_type& _M_result; 01245 std::function<void()> _M_fn; 01246 }; 01247 01248 template<typename _Res, typename... _Args> 01249 struct __future_base::_Task_state<_Res(_Args...)> final 01250 : __future_base::_State_base 01251 { 01252 typedef _Res _Res_type; 01253 01254 _Task_state(std::function<_Res(_Args...)> __task) 01255 : _M_result(new _Result<_Res>()), _M_task(std::move(__task)) 01256 { } 01257 01258 template<typename _Func, typename _Alloc> 01259 _Task_state(_Func&& __task, const _Alloc& __a) 01260 : _M_result(_S_allocate_result<_Res>(__a)), 01261 _M_task(allocator_arg, __a, std::move(__task)) 01262 { } 01263 01264 void 01265 _M_run(_Args... __args) 01266 { 01267 // bound arguments decay so wrap lvalue references 01268 auto __boundfn = std::__bind_simple(std::ref(_M_task), 01269 _S_maybe_wrap_ref(std::forward<_Args>(__args))...); 01270 auto __setter = _S_task_setter(_M_result, std::move(__boundfn)); 01271 _M_set_result(std::move(__setter)); 01272 } 01273 01274 typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type; 01275 _Ptr_type _M_result; 01276 std::function<_Res(_Args...)> _M_task; 01277 01278 template<typename _Tp> 01279 static reference_wrapper<_Tp> 01280 _S_maybe_wrap_ref(_Tp& __t) 01281 { return std::ref(__t); } 01282 01283 template<typename _Tp> 01284 static typename enable_if<!is_lvalue_reference<_Tp>::value, 01285 _Tp>::type&& 01286 _S_maybe_wrap_ref(_Tp&& __t) 01287 { return std::forward<_Tp>(__t); } 01288 }; 01289 01290 template<typename _Task, typename _Fn, bool 01291 = is_same<_Task, typename decay<_Fn>::type>::value> 01292 struct __constrain_pkgdtask 01293 { typedef void __type; }; 01294 01295 template<typename _Task, typename _Fn> 01296 struct __constrain_pkgdtask<_Task, _Fn, true> 01297 { }; 01298 01299 /// packaged_task 01300 template<typename _Res, typename... _ArgTypes> 01301 class packaged_task<_Res(_ArgTypes...)> 01302 { 01303 typedef __future_base::_Task_state<_Res(_ArgTypes...)> _State_type; 01304 shared_ptr<_State_type> _M_state; 01305 01306 public: 01307 // Construction and destruction 01308 packaged_task() noexcept { } 01309 01310 template<typename _Allocator> 01311 explicit 01312 packaged_task(allocator_arg_t, const _Allocator& __a) noexcept 01313 { } 01314 01315 template<typename _Fn, typename = typename 01316 __constrain_pkgdtask<packaged_task, _Fn>::__type> 01317 explicit 01318 packaged_task(_Fn&& __fn) 01319 : _M_state(std::make_shared<_State_type>(std::forward<_Fn>(__fn))) 01320 { } 01321 01322 template<typename _Fn, typename _Allocator, typename = typename 01323 __constrain_pkgdtask<packaged_task, _Fn>::__type> 01324 explicit 01325 packaged_task(allocator_arg_t, const _Allocator& __a, _Fn&& __fn) 01326 : _M_state(std::allocate_shared<_State_type>(__a, 01327 std::forward<_Fn>(__fn))) 01328 { } 01329 01330 ~packaged_task() 01331 { 01332 if (static_cast<bool>(_M_state) && !_M_state.unique()) 01333 _M_state->_M_break_promise(std::move(_M_state->_M_result)); 01334 } 01335 01336 // No copy 01337 packaged_task(const packaged_task&) = delete; 01338 packaged_task& operator=(const packaged_task&) = delete; 01339 01340 template<typename _Allocator> 01341 explicit 01342 packaged_task(allocator_arg_t, const _Allocator&, 01343 const packaged_task&) = delete; 01344 01345 // Move support 01346 packaged_task(packaged_task&& __other) noexcept 01347 { this->swap(__other); } 01348 01349 template<typename _Allocator> 01350 explicit 01351 packaged_task(allocator_arg_t, const _Allocator&, 01352 packaged_task&& __other) noexcept 01353 { this->swap(__other); } 01354 01355 packaged_task& operator=(packaged_task&& __other) noexcept 01356 { 01357 packaged_task(std::move(__other)).swap(*this); 01358 return *this; 01359 } 01360 01361 void 01362 swap(packaged_task& __other) noexcept 01363 { _M_state.swap(__other._M_state); } 01364 01365 bool 01366 valid() const noexcept 01367 { return static_cast<bool>(_M_state); } 01368 01369 // Result retrieval 01370 future<_Res> 01371 get_future() 01372 { return future<_Res>(_M_state); } 01373 01374 // Execution 01375 void 01376 operator()(_ArgTypes... __args) 01377 { 01378 __future_base::_State_base::_S_check(_M_state); 01379 _M_state->_M_run(std::forward<_ArgTypes>(__args)...); 01380 } 01381 01382 void 01383 reset() 01384 { 01385 __future_base::_State_base::_S_check(_M_state); 01386 packaged_task(std::move(_M_state->_M_task)).swap(*this); 01387 } 01388 }; 01389 01390 /// swap 01391 template<typename _Res, typename... _ArgTypes> 01392 inline void 01393 swap(packaged_task<_Res(_ArgTypes...)>& __x, 01394 packaged_task<_Res(_ArgTypes...)>& __y) noexcept 01395 { __x.swap(__y); } 01396 01397 template<typename _Res, typename _Alloc> 01398 struct uses_allocator<packaged_task<_Res>, _Alloc> 01399 : public true_type { }; 01400 01401 01402 template<typename _BoundFn, typename _Res> 01403 class __future_base::_Deferred_state final 01404 : public __future_base::_State_base 01405 { 01406 public: 01407 explicit 01408 _Deferred_state(_BoundFn&& __fn) 01409 : _M_result(new _Result<_Res>()), _M_fn(std::move(__fn)) 01410 { } 01411 01412 private: 01413 typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type; 01414 _Ptr_type _M_result; 01415 _BoundFn _M_fn; 01416 01417 virtual void 01418 _M_run_deferred() 01419 { 01420 // safe to call multiple times so ignore failure 01421 _M_set_result(_S_task_setter(_M_result, _M_fn), true); 01422 } 01423 }; 01424 01425 class __future_base::_Async_state_common : public __future_base::_State_base 01426 { 01427 protected: 01428 #ifdef _GLIBCXX_HAVE_TLS 01429 ~_Async_state_common(); 01430 #else 01431 ~_Async_state_common() { _M_join(); } 01432 #endif 01433 01434 // Allow non-timed waiting functions to block until the thread completes, 01435 // as if joined. 01436 virtual void _M_run_deferred() { _M_join(); } 01437 01438 void _M_join() { std::call_once(_M_once, &thread::join, ref(_M_thread)); } 01439 01440 thread _M_thread; 01441 once_flag _M_once; 01442 }; 01443 01444 template<typename _BoundFn, typename _Res> 01445 class __future_base::_Async_state_impl final 01446 : public __future_base::_Async_state_common 01447 { 01448 public: 01449 explicit 01450 _Async_state_impl(_BoundFn&& __fn) 01451 : _M_result(new _Result<_Res>()), _M_fn(std::move(__fn)) 01452 { 01453 _M_thread = std::thread{ [this] { 01454 _M_set_result(_S_task_setter(_M_result, _M_fn)); 01455 } }; 01456 } 01457 01458 private: 01459 typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type; 01460 _Ptr_type _M_result; 01461 _BoundFn _M_fn; 01462 }; 01463 01464 template<typename _BoundFn> 01465 inline std::shared_ptr<__future_base::_State_base> 01466 __future_base::_S_make_deferred_state(_BoundFn&& __fn) 01467 { 01468 typedef typename remove_reference<_BoundFn>::type __fn_type; 01469 typedef _Deferred_state<__fn_type> __state_type; 01470 return std::make_shared<__state_type>(std::move(__fn)); 01471 } 01472 01473 template<typename _BoundFn> 01474 inline std::shared_ptr<__future_base::_State_base> 01475 __future_base::_S_make_async_state(_BoundFn&& __fn) 01476 { 01477 typedef typename remove_reference<_BoundFn>::type __fn_type; 01478 typedef _Async_state_impl<__fn_type> __state_type; 01479 return std::make_shared<__state_type>(std::move(__fn)); 01480 } 01481 01482 01483 /// async 01484 template<typename _Fn, typename... _Args> 01485 future<typename result_of<_Fn(_Args...)>::type> 01486 async(launch __policy, _Fn&& __fn, _Args&&... __args) 01487 { 01488 typedef typename result_of<_Fn(_Args...)>::type result_type; 01489 std::shared_ptr<__future_base::_State_base> __state; 01490 if ((__policy & (launch::async|launch::deferred)) == launch::async) 01491 { 01492 __state = __future_base::_S_make_async_state(std::__bind_simple( 01493 std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)); 01494 } 01495 else 01496 { 01497 __state = __future_base::_S_make_deferred_state(std::__bind_simple( 01498 std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)); 01499 } 01500 return future<result_type>(__state); 01501 } 01502 01503 /// async, potential overload 01504 template<typename _Fn, typename... _Args> 01505 inline typename 01506 __async_sfinae_helper<typename decay<_Fn>::type, _Fn, _Args...>::type 01507 async(_Fn&& __fn, _Args&&... __args) 01508 { 01509 return async(launch::async|launch::deferred, std::forward<_Fn>(__fn), 01510 std::forward<_Args>(__args)...); 01511 } 01512 01513 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 01514 // && ATOMIC_INT_LOCK_FREE 01515 01516 // @} group futures 01517 _GLIBCXX_END_NAMESPACE_VERSION 01518 } // namespace 01519 01520 #endif // __GXX_EXPERIMENTAL_CXX0X__ 01521 01522 #endif // _GLIBCXX_FUTURE