future_ref.qbk 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632
  1. [/
  2. (C) Copyright 2008-11 Anthony Williams.
  3. (C) Copyright 2012-2015 Vicente J. Botet Escriba.
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt).
  7. ]
  8. [///////////////////////////////////]
  9. [section:reference Futures Reference]
  10. //#include <boost/thread/future.hpp>
  11. namespace boost
  12. {
  13. namespace future_state // EXTENSION
  14. {
  15. enum state {uninitialized, waiting, ready, moved};
  16. }
  17. enum class future_errc
  18. {
  19. broken_promise,
  20. future_already_retrieved,
  21. promise_already_satisfied,
  22. no_state
  23. };
  24. enum class launch
  25. {
  26. none = unspecified,
  27. async = unspecified,
  28. deferred = unspecified,
  29. executor = unspecified,
  30. inherit = unspecified,
  31. any = async | deferred
  32. };
  33. enum class future_status {
  34. ready, timeout, deferred
  35. };
  36. namespace system
  37. {
  38. template <>
  39. struct is_error_code_enum<future_errc> : public true_type {};
  40. error_code make_error_code(future_errc e);
  41. error_condition make_error_condition(future_errc e);
  42. }
  43. const system::error_category& future_category();
  44. class future_error;
  45. class exceptional_ptr;
  46. template <typename R>
  47. class promise;
  48. template <typename R>
  49. void swap(promise<R>& x, promise<R>& y) noexcept;
  50. namespace container {
  51. template <class R, class Alloc>
  52. struct uses_allocator<promise<R>, Alloc>:: true_type;
  53. }
  54. template <typename R>
  55. class future;
  56. template <typename R>
  57. class shared_future;
  58. template <typename S>
  59. class packaged_task;
  60. template <class S> void swap(packaged_task<S>&, packaged_task<S>&) noexcept;
  61. template <class S, class Alloc>
  62. struct uses_allocator<packaged_task <S>, Alloc>;
  63. template <class F>
  64. future<typename result_of<typename decay<F>::type()>::type>
  65. async(F f);
  66. template <class F>
  67. future<typename result_of<typename decay<F>::type()>::type>
  68. async(launch policy, F f);
  69. template <class F, class... Args>
  70. future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
  71. async(F&& f, Args&&... args);
  72. template <class F, class... Args>
  73. future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
  74. async(launch policy, F&& f, Args&&... args);
  75. template <class Executor, class F, class... Args>
  76. future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
  77. async(Executor &ex, F&& f, Args&&... args);
  78. template<typename Iterator>
  79. void wait_for_all(Iterator begin,Iterator end); // EXTENSION
  80. template<typename F1,typename... FS>
  81. void wait_for_all(F1& f1,Fs&... fs); // EXTENSION
  82. template<typename Iterator>
  83. Iterator wait_for_any(Iterator begin,Iterator end); // EXTENSION
  84. template<typename F1,typename... Fs>
  85. unsigned wait_for_any(F1& f1,Fs&... fs); // EXTENSION
  86. template <class InputIterator>
  87. future<std::vector<typename InputIterator::value_type::value_type>>
  88. when_all(InputIterator first, InputIterator last);
  89. template <typename... T>
  90. future<std::tuple<decay_t<T>...> when_all(T&&... futures);
  91. template <class InputIterator>
  92. future<std::vector<typename InputIterator::value_type::value_type>>
  93. when_any(InputIterator first, InputIterator last); // EXTENSION
  94. template <typename... T>
  95. future<std::tuple<decay_t<T>...> when_any(T&&... futures);
  96. template <typename T>
  97. future<typename decay<T>::type> make_future(T&& value); // DEPRECATED
  98. future<void> make_future(); // DEPRECATED
  99. template <typename T>
  100. future<typename decay<T>::type> make_ready_future(T&& value); // EXTENSION
  101. future<void> make_ready_future(); // EXTENSION
  102. exceptional_ptr make_exceptional_future(exception_ptr ex); // EXTENSION
  103. template <typename E>
  104. exceptional_ptr make_exceptional_future(E ex); // EXTENSION
  105. exceptional_ptr make_exceptional_future(); // EXTENSION
  106. template <typename T>
  107. shared_future<typename decay<T>::type> make_shared_future(T&& value); // DEPRECATED
  108. shared_future<void> make_shared_future(); // DEPRECATED
  109. [////////////////////////////////////////]
  110. [section:future_state Enumeration `state`]
  111. namespace future_state
  112. {
  113. enum state {uninitialized, waiting, ready, moved};
  114. }
  115. [endsect]
  116. [/////////////////////////////////////////////]
  117. [section:future_errc Enumeration `future_errc`]
  118. enum class future_errc
  119. {
  120. broken_promise = implementation defined,
  121. future_already_retrieved = implementation defined,
  122. promise_already_satisfied = implementation defined,
  123. no_state = implementation defined
  124. }
  125. The enum values of future_errc are distinct and not zero.
  126. [endsect]
  127. [///////////////////////////////////]
  128. [section:launch Enumeration `launch`]
  129. enum class launch
  130. {
  131. none = unspecified,
  132. async = unspecified,
  133. deferred = unspecified,
  134. executor = unspecified,
  135. inherit = unspecified,
  136. any = async | deferred
  137. };
  138. The enum type launch is a bitmask type with launch::async and launch::deferred denoting individual bits.
  139. A future created with `promise<>` or with a `packaged_task<>` or with `make_ready_future`/`make_exceptional_future` (has no associated launch policy), has an implicit a launch policy of `launch::none`.
  140. A future created by `async(launch::async, ...)` or `::then(launch::async, ...)` has associated a launch policy `launch::async`.
  141. A future created by `async(launch::deferred, ...)` or `::then(launch::deferred, ...)` has associated a launch policy `launch::deferred`.
  142. A future created by `async(Executor, ...)` or `::then(Executor, ...)` or `::then(launch::executor, ...)` has associated a launch policy `launch::executor`.
  143. A future created by `async(...)` or `::then(...)` has associated a launch policy `launch::none`.
  144. A future created by `::then(launch::inherit, ...)` has associated a launch policy parent future.
  145. The `executor` and the `inherit` launch policies have a sense only can be user only on `then()`.
  146. [endsect]
  147. [///////////////////////////////////////////////////////////////////////////]
  148. [section:is_error_code_enum Specialization `is_error_code_enum<future_errc>`]
  149. namespace system
  150. {
  151. template <>
  152. struct is_error_code_enum<future_errc> : public true_type {};
  153. }
  154. [endsect]
  155. [///////////////////////////////////////////////////////////////]
  156. [section:make_error_code Non-member function `make_error_code()`]
  157. namespace system
  158. {
  159. error_code make_error_code(future_errc e);
  160. }
  161. [variablelist
  162. [[Returns:] [`error_code(static_cast<int>(e), future_category())`.]]
  163. ]
  164. [endsect]
  165. [/////////////////////////////////////////////////////////////////////////]
  166. [section:make_error_condition Non-member function `make_error_condition()`]
  167. namespace system
  168. {
  169. error_condition make_error_condition(future_errc e);
  170. }
  171. [variablelist
  172. [[Returns:] [`error_condition(static_cast<int>(e), future_category())`.]]
  173. ]
  174. [endsect]
  175. [///////////////////////////////////////////////////////////////]
  176. [section:future_category Non-member function `future_category()`]
  177. const system::error_category& future_category();
  178. [variablelist
  179. [[Returns:] [A reference to an object of a type derived from class error_category.]]
  180. [[Notes:] [The object's `default_error_condition` and equivalent virtual functions behave as specified for the class `system::error_category`.
  181. The object's `name` virtual function returns a pointer to the string "future".]]
  182. ]
  183. [endsect]
  184. [/////////////////////////////////////////]
  185. [section:future_error Class `future_error`]
  186. class future_error
  187. : public std::logic_error
  188. {
  189. public:
  190. future_error(system::error_code ec);
  191. const system::error_code& code() const no_except;
  192. };
  193. [///////////////////////////////]
  194. [section:constructor Constructor]
  195. future_error(system::error_code ec);
  196. [variablelist
  197. [[Effects:] [Constructs a future_error.]]
  198. [[Postconditions:] [`code()==ec` ]]
  199. [[Throws:] [Nothing.]]
  200. ]
  201. [endsect]
  202. [/////////////////////////////////////]
  203. [section:code Member function `code()`]
  204. const system::error_code& code() const no_except;
  205. [variablelist
  206. [[Returns:] [The value of `ec` that was passed to the object's constructor.]]
  207. ]
  208. [endsect]
  209. [endsect]
  210. [/////////////////////////////////////////////////]
  211. [section:future_status Enumeration `future_status`]
  212. enum class future_status {
  213. ready, timeout, deferred
  214. };
  215. [endsect]
  216. [/////////////////////////////////////////]
  217. [section:future_error Class `exceptional_ptr` EXPERIMENTAL]
  218. class exceptional_ptr
  219. {
  220. public:
  221. exceptional_ptr();
  222. explicit exceptional_ptr(exception_ptr ex);
  223. template <class E>
  224. explicit exceptional_ptr(E&& ex);
  225. };
  226. [///////////////////////////////]
  227. [section:constructor Constructor]
  228. exceptional_ptr();
  229. explicit exceptional_ptr(exception_ptr ex);
  230. template <class E>
  231. explicit exceptional_ptr(E&& ex);
  232. [variablelist
  233. [[Effects:] [The exception that is passed in to the constructor or the current exception if no parameter is moved into the constructed `exceptional_ptr` if it is an rvalue. Otherwise the exception is copied into the constructed `exceptional_ptr`.]]
  234. [[Postconditions:] [
  235. `valid() == true && is_ready() = true && has_value() = false`
  236. ]]
  237. [[Throws:] [Nothing.]]
  238. ]
  239. [endsect]
  240. [endsect]
  241. [////////////////////////////////////////////////////]
  242. [section:unique_future __unique_future class template]
  243. template <typename R>
  244. class __unique_future__
  245. {
  246. public:
  247. typedef R value_type; // EXTENSION
  248. __unique_future__(__unique_future__ const& rhs) = delete;
  249. __unique_future__& operator=(__unique_future__ const& rhs) = delete;
  250. __unique_future__() noexcept;
  251. ~__unique_future__();
  252. // move support
  253. __unique_future__(__unique_future__ && other) noexcept;
  254. explicit __unique_future__(__unique_future__<__unique_future__<R>>&& rhs); // EXTENSION
  255. __unique_future__& operator=(__unique_future__ && other) noexcept;
  256. // factories
  257. shared_future<R> share();
  258. template<typename F>
  259. __unique_future__<typename boost::result_of<F(__unique_future__)>::type>
  260. then(F&& func); // EXTENSION
  261. template<typename Ex, typename F>
  262. __unique_future__<typename boost::result_of<F(__unique_future__)>::type>
  263. then(Ex& executor, F&& func); // EXTENSION
  264. template<typename F>
  265. __unique_future__<typename boost::result_of<F(__unique_future__)>::type>
  266. then(launch policy, F&& func); // EXTENSION
  267. see below unwrap(); // EXTENSION
  268. __unique_future__ fallback_to(); // EXTENSION
  269. void swap(__unique_future__& other) noexcept;
  270. // retrieving the value
  271. see below get();
  272. see below get_or(see below); // EXTENSION
  273. exception_ptr get_exception_ptr(); // EXTENSION
  274. // functions to check state
  275. bool valid() const noexcept;
  276. bool is_ready() const; // EXTENSION
  277. bool has_exception() const; // EXTENSION
  278. bool has_value() const; // EXTENSION
  279. // waiting for the result to be ready
  280. void wait() const;
  281. template <class Rep, class Period>
  282. future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
  283. template <class Clock, class Duration>
  284. future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
  285. #if defined BOOST_THREAD_USES_DATE_TIME
  286. template<typename Duration>
  287. bool timed_wait(Duration const& rel_time) const; // DEPRECATED SINCE V3.0.0
  288. bool timed_wait_until(boost::system_time const& abs_time) const; // DEPRECATED SINCE V3.0.0
  289. #endif
  290. typedef future_state::state state; // EXTENSION
  291. state get_state() const; // EXTENSION
  292. };
  293. [///////////////////////////////////////////////]
  294. [section:default_constructor Default Constructor]
  295. __unique_future__();
  296. [variablelist
  297. [[Effects:] [Constructs an uninitialized __unique_future__.]]
  298. [[Postconditions:] [[unique_future_is_ready_link `this->is_ready`] returns `false`. [unique_future_get_state_link
  299. `this->get_state()`] returns __uninitialized__.]]
  300. [[Throws:] [Nothing.]]
  301. ]
  302. [endsect]
  303. [/////////////////////////////]
  304. [section:destructor Destructor]
  305. ~__unique_future__();
  306. [variablelist
  307. [[Effects:] [Destroys `*this`.]]
  308. [[Throws:] [Nothing.]]
  309. ]
  310. [endsect]
  311. [/////////////////////////////////////////]
  312. [section:move_constructor Move Constructor]
  313. __unique_future__(__unique_future__ && other);
  314. [variablelist
  315. [[Effects:] [Constructs a new __unique_future__, and transfers ownership of the shared state associated with `other` to `*this`.]]
  316. [[Postconditions:] [[unique_future_get_state_link `this->get_state()`] returns the value of `other->get_state()` prior to the
  317. call. `other->get_state()` returns __uninitialized__. If `other` was associated with a shared state, that result is now
  318. associated with `*this`. `other` is not associated with any shared state.]]
  319. [[Throws:] [Nothing.]]
  320. [[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
  321. ]
  322. [endsect]
  323. [///////////////////////////////////////////////////////////////////]
  324. [section:unwrap_move_constructor Unwrap Move Constructor - EXTENSION]
  325. explicit __unique_future__(__unique_future__<__unique_future__<R>>&& other); // EXTENSION
  326. [warning This constructor is experimental and subject to change in future versions.
  327. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
  328. [variablelist
  329. [[Requires:] [`other.valid()`.]
  330. [[Effects:] [Constructs a new __unique_future__, and transfers ownership of the shared state associated with `other` and unwrapping the inner future (see `unwrap()`).]]
  331. [[Postconditions:] [[unique_future_get_state_link `this->get_state()`] returns the value of `other->get_state()` prior to the
  332. call. `other->get_state()` returns __uninitialized__. The associated shared state is now
  333. unwrapped and the inner future shared state is associated with `*this`. `other` is not associated with any shared state, `! other.valid()`.]]
  334. [[Throws:] [Nothing.]]
  335. [[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
  336. ]
  337. [endsect]
  338. [////////////////////////////////////////////////]
  339. [section:move_assignment Move Assignment Operator]
  340. __unique_future__& operator=(__unique_future__ && other);
  341. [variablelist
  342. [[Effects:] [Transfers ownership of the shared state associated with `other` to `*this`.]]
  343. [[Postconditions:] [[unique_future_get_state_link `this->get_state()`] returns the value of `other->get_state()` prior to the
  344. call. `other->get_state()` returns __uninitialized__. If `other` was associated with a shared state, that result is now
  345. associated with `*this`. `other` is not associated with any shared state. If `*this` was associated with an asynchronous
  346. result prior to the call, that result no longer has an associated __unique_future__ instance.]]
  347. [[Throws:] [Nothing.]]
  348. [[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
  349. ]
  350. [endsect]
  351. [/////////////////////////////////////]
  352. [section:swap Member function `swap()`]
  353. void swap(__unique_future__ & other) no_except;
  354. [variablelist
  355. [[Effects:] [Swaps ownership of the shared states associated with `other` and `*this`.]]
  356. [[Postconditions:] [[unique_future_get_state_link `this->get_state()`] returns the value of `other->get_state()` prior to the
  357. call. `other->get_state()` returns the value of `this->get_state()` prior to the call. If `other` was associated with a
  358. shared state, that result is now associated with `*this`, otherwise `*this` has no associated result. If `*this` was
  359. associated with a shared state, that result is now associated with `other`, otherwise `other` has no associated result.]]
  360. [[Throws:] [Nothing.]]
  361. ]
  362. [endsect]
  363. [///////////////////////////////////]
  364. [section:get Member function `get()`]
  365. R get();
  366. R& __unique_future__<R&>::get();
  367. void __unique_future__<void>::get();
  368. [variablelist
  369. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready as-if by a call to
  370. __unique_future_wait__, and retrieves the result (whether that is a value or an exception).]]
  371. [[Returns:] [
  372. - `__unique_future__<R&>::get()` return the stored reference.
  373. - `__unique_future__<void>::get()`, there is no return value.
  374. - `__unique_future__<R>::get()` returns an rvalue-reference to the value stored in the shared state.
  375. ]]
  376. [[Postconditions:] [[unique_future_is_ready_link `this->is_ready()`] returns `true`. [unique_future_get_state_link
  377. `this->get_state()`] returns __ready__.]]
  378. [[Throws:] [
  379. - __future_uninitialized__ if `*this` is not associated with a shared state.
  380. - __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  381. - Any exception stored in the shared state in place of a value.
  382. ]]
  383. [[Notes:] [`get()` is an ['interruption point].]]
  384. ]
  385. [endsect]
  386. [/////////////////////////////////////////////////////]
  387. [section:get_or Member function `get_or()` - EXTENSION]
  388. R get_or(R&& v); // EXTENSION
  389. R get_or(R const& v); // EXTENSION
  390. R& __unique_future__<R&>::get_or(R& v); // EXTENSION
  391. void __unique_future__<void>::get_or(); // EXTENSION
  392. [warning These functions are experimental and subject to change in future versions.
  393. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
  394. [variablelist
  395. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready as-if by a call to
  396. __unique_future_wait__, and depending on whether the shared state `has_value()` the retrieves the result.]]
  397. [[Returns:] [
  398. - `__unique_future__<R&>::get_or(v)` return the stored reference if has_value() and the passes parameter otherwise.
  399. - `__unique_future__<void>::get_or()`, there is no return value, but the function doesn't throws even if the shared state contained an exception.
  400. - `__unique_future__<R>::get_or(v)` returns an rvalue-reference to the value stored in the shared state if `has_value()` and an rvalue-reference build with the parameter `v`.
  401. ]]
  402. [[Postconditions:] [[unique_future_is_ready_link `this->is_ready()`] returns `true`. [unique_future_get_state_link
  403. `this->get_state()`] returns __ready__.]]
  404. [[Throws:] [
  405. - __future_uninitialized__ if `*this` is not associated with a shared state.
  406. ]]
  407. [[Notes:] [`get_or()` is an ['interruption point].]]
  408. ]
  409. [endsect]
  410. [/////////////////////////////////////]
  411. [section:wait Member function `wait()`]
  412. void wait() const;
  413. [variablelist
  414. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready. If the result is not ready on
  415. entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
  416. [[Throws:] [
  417. - __future_uninitialized__ if `*this` is not associated with a shared state.
  418. - __thread_interrupted__ if the result
  419. associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  420. - Any exception thrown by the ['wait callback] if such a callback is called.]]
  421. [[Postconditions:] [[unique_future_is_ready_link `this->is_ready()`] returns `true`. [unique_future_get_state_link
  422. `this->get_state()`] returns __ready__.]]
  423. [[Notes:] [`wait()` is an ['interruption point].]]
  424. ]
  425. [endsect]
  426. [//////////////////////////////////////////////////////////////////////////////////]
  427. [section:timed_wait_duration Member function `timed_wait()` DEPRECATED SINCE V3.0.0]
  428. template<typename Duration>
  429. bool timed_wait(Duration const& wait_duration);
  430. [warning
  431. DEPRECATED since 3.00.
  432. Use instead __wait_for.
  433. ]
  434. [variablelist
  435. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time specified by
  436. `wait_duration` has elapsed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is
  437. invoked prior to waiting.]]
  438. [[Returns:] [`true` if `*this` is associated with a shared state, and that result is ready before the specified time has
  439. elapsed, `false` otherwise.]]
  440. [[Throws:] [
  441. - __future_uninitialized__ if `*this` is not associated with a shared state.
  442. - __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  443. - Any exception thrown by the ['wait callback] if such a callback is called.]]
  444. [[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and
  445. [unique_future_get_state_link `this->get_state()`] returns __ready__.]]
  446. [[Notes:] [`timed_wait()` is an ['interruption point]. `Duration` must be a type that meets the Boost.DateTime time duration requirements.]]
  447. ]
  448. [endsect]
  449. [//////////////////////////////////////////////////////////////////////////////////]
  450. [section:timed_wait_absolute Member function `timed_wait()` DEPRECATED SINCE V3.0.0]
  451. bool timed_wait(boost::system_time const& wait_timeout);
  452. [warning
  453. DEPRECATED since 3.00.
  454. Use instead __wait_until.
  455. ]
  456. [variablelist
  457. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time point specified by
  458. `wait_timeout` has passed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked
  459. prior to waiting.]]
  460. [[Returns:] [`true` if `*this` is associated with a shared state, and that result is ready before the specified time has
  461. passed, `false` otherwise.]]
  462. [[Throws:] [
  463. - __future_uninitialized__ if `*this` is not associated with a shared state.
  464. - __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  465. - Any exception thrown by the ['wait callback] if such a callback is called.]]
  466. [[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and
  467. [unique_future_get_state_link `this->get_state()`] returns __ready__.]]
  468. [[Notes:] [`timed_wait()` is an ['interruption point].]]
  469. ]
  470. [endsect]
  471. [/////////////////////////////////////////////]
  472. [section:wait_for Member function `wait_for()`]
  473. template <class Rep, class Period>
  474. future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
  475. [variablelist
  476. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time specified by
  477. `wait_duration` has elapsed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is
  478. invoked prior to waiting.]]
  479. [[Returns:] [
  480. - `future_status::deferred` if the shared state contains a deferred function. (Not implemented yet)
  481. - `future_status::ready` if the shared state is ready.
  482. - `future_status::timeout` if the function is returning because the relative timeout specified by `rel_time` has expired.
  483. ]]
  484. [[Throws:] [
  485. - __future_uninitialized__ if `*this` is not associated with a shared state.
  486. - __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  487. - Any exception thrown by the ['wait callback] if such a callback is called.]]
  488. [[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and
  489. [unique_future_get_state_link `this->get_state()`] returns __ready__.]]
  490. [[Notes:] [`wait_for()` is an ['interruption point]. `Duration` must be a type that meets the Boost.DateTime time duration requirements.]]
  491. ]
  492. [endsect]
  493. [/////////////////////////////////////////////////]
  494. [section:wait_until Member function `wait_until()`]
  495. template <class Clock, class Duration>
  496. future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
  497. [variablelist
  498. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time point specified by
  499. `wait_timeout` has passed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked
  500. prior to waiting.]]
  501. [[Returns:] [
  502. - `future_status::deferred` if the shared state contains a deferred function. (Not implemented yet)
  503. - `future_status::ready` if the shared state is ready.
  504. - `future_status::timeout` if the function is returning because the absolute timeout specified by `absl_time` has reached.
  505. ]]
  506. [[Throws:] [
  507. - __future_uninitialized__ if `*this` is not associated with a shared state.
  508. - __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  509. - Any exception thrown by the ['wait callback] if such a callback is called.]]
  510. [[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and
  511. [unique_future_get_state_link `this->get_state()`] returns __ready__.]]
  512. [[Notes:] [`wait_until()` is an ['interruption point].]]
  513. ]
  514. [endsect]
  515. [///////////////////////////////////////]
  516. [section:valid Member function `valid()`]
  517. bool valid() const noexcept;
  518. [variablelist
  519. [[Returns:] [`true` if `*this` is associated with a shared state, `false`
  520. otherwise.]]
  521. [[Remarks:] [The result of this function is not stable and that the future could become invalid even if the function returned true or vice-versa.]]
  522. [[Throws:] [Nothing.]]
  523. ]
  524. [endsect]
  525. [///////////////////////////////////////////////////////]
  526. [section:is_ready Member function `is_ready()` EXTENSION]
  527. bool is_ready() const;
  528. [variablelist
  529. [[Returns:] [`true` if `*this` is associated with a shared state and that result is ready for retrieval, `false`
  530. otherwise.]]
  531. [[Remarks:] [The result of this function is not stable and that the future could become not ready even if the function returned true or vice-versa.]]
  532. [[Throws:] [Nothing.]]
  533. ]
  534. [endsect]
  535. [/////////////////////////////////////////////////////////]
  536. [section:has_value Member function `has_value()` EXTENSION]
  537. bool has_value() const;
  538. [variablelist
  539. [[Returns:] [`true` if `*this` is associated with a shared state, that result is ready for retrieval, and the result is a
  540. stored value, `false` otherwise.]]
  541. [[Remarks:] [The result of this function is not stable and the future could lost its value even if the function returned true or vice-versa.]]
  542. [[Throws:] [Nothing.]]
  543. ]
  544. [endsect]
  545. [/////////////////////////////////////////////////////////////////]
  546. [section:has_exception Member function `has_exception()` EXTENSION]
  547. bool has_exception() const;
  548. [variablelist
  549. [[Returns:] [`true` if `*this` is associated with a shared state, that result is ready for retrieval, and the result is a
  550. stored exception, `false` otherwise.]]
  551. [[Remarks:] [The result of this function is not stable and the future could lost its exception even if the function returned true or vice-versa.]]
  552. [[Throws:] [Nothing.]]
  553. ]
  554. [endsect]
  555. [/////////////////////////////////////////////////////////////////]
  556. [section:get_exception_ptr Member function `get_exception_ptr()` EXTENSION]
  557. exception_ptr get_exception_ptr();
  558. [variablelist
  559. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready. If the result is not ready on
  560. entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
  561. [[Returns:] [an exception_ptr, storing or not an exception.]]
  562. [[Remarks:] [The result of this function is not stable and the future could lost its exception even if the function returned a valid `exception_ptr` or vice-versa.]]
  563. [[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
  564. ]
  565. [endsect]
  566. [/////////////////////////////////////////////////////////]
  567. [section:get_state Member function `get_state()` EXTENSION]
  568. future_state::state get_state();
  569. [variablelist
  570. [[Effects:] [Determine the state of the shared state associated with `*this`, if any.]]
  571. [[Returns:] [__uninitialized__ if `*this` is not associated with a shared state. __ready__ if the shared state
  572. associated with `*this` is ready for retrieval, __waiting__ otherwise.]]
  573. [[Remarks:] [The result of this function is not stable.]]
  574. [[Throws:] [Nothing.]]
  575. ]
  576. [endsect]
  577. [///////////////////////////////////////]
  578. [section:share Member function `share()`]
  579. shared_future<R> share();
  580. [variablelist
  581. [[Returns:] [`shared_future<R>(boost::move(*this))`.]]
  582. [[Postconditions:] [`this->valid() == false`.]]
  583. ]
  584. [endsect]
  585. [/////////////////////////////////////////////////]
  586. [section:then Member function `then()` - EXTENSION]
  587. template<typename F>
  588. __unique_future__<typename boost::result_of<F(__unique_future__)>::type>
  589. then(F&& func); // EXTENSION
  590. template<typename Ex, typename F>
  591. __unique_future__<typename boost::result_of<F(__unique_future__)>::type>
  592. then(Ex& executor, F&& func); // EXTENSION
  593. template<typename F>
  594. __unique_future__<typename boost::result_of<F(__unique_future__)>::type>
  595. then(launch policy, F&& func); // EXTENSION
  596. [warning These functions are experimental and subject to change in future versions.
  597. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
  598. [note These functions are based on the [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3634.pdf [*N3634 - Improvements to std::future<T> and related APIs]] C++1y proposal by N. Gustafsson, A. Laksberg, H. Sutter, S. Mithani.]
  599. [variablelist
  600. [[Notes:] [The three functions differ only by input parameters. The first only takes a callable object which accepts a
  601. future object as a parameter. The second function takes an executor as the first parameter and a callable object as
  602. the second parameter. The third function takes a launch policy as the first parameter and a callable object as the
  603. second parameter.]]
  604. [[Requires:] [`INVOKE(DECAY_COPY (std::forward<F>(func)), std::move(*this))` shall be a valid expression.]]
  605. [[Effects:] [
  606. All the functions create a shared state that is associated with the returned future object. Additionally,
  607. - When the object's shared state is ready, the continuation
  608. `INVOKE(DECAY_COPY(std::forward<F>(func)), std::move(*this))` is called depending on the overload (see below) with the call to DECAY_COPY() being evaluated in the thread that called then.
  609. - Any value returned from the continuation is stored as the result in the shared state of the resulting `future`.
  610. Any exception propagated from the execution of the continuation is stored as the exceptional result in the shared state of the resulting `future`.
  611. The continuation launches according to the specified policy or executor or noting.
  612. - When the launch policy is `launch::none` the continuation is called on an unspecified thread of execution.
  613. - When the launch policy is `launch::async` the continuation is called on a new thread of execution.
  614. - When the launch policy is `launch::deferred` the continuation is called on demand.
  615. - When the launch policy is `launch::executor` the continuation is called on one of the thread of execution of the executor.
  616. - When the launch policy is `launch::inherit` the continuation inherits the parent's launch policy or executor.
  617. - When the executor or launch policy is not provided (first overload) is if as if launch::none was specified.
  618. - When the executor is provided (second overload) the continuation is called on one of the thread of execution of the executor.
  619. - If the parent has a policy of `launch::deferred` and the continuation does not have a specified launch policy
  620. executor, then the parent is filled by immediately calling `.wait()`, and the policy of the antecedent is
  621. `launch::deferred`.
  622. ]]
  623. [[Returns:] [An object of type `__unique_future__<typename boost::result_of<F(__unique_future__)>` that refers to the shared state created by the continuation.]]
  624. [[Notes:] [
  625. - Note that nested futures are not implicitly unwrapped yet. This could be subject to change in future versions.
  626. - The returned futures behave as the ones returned from boost::async, the destructor of the future object returned from then will block. This could be subject to change in future versions.
  627. ]]
  628. [[Postconditions:] [
  629. - The `__unique_future__` object passed to the parameter of the continuation function is a copy of the original `__unique_future__`.
  630. - `valid() == false` on original future; `valid() == true` on the `future` returned from then.
  631. [/ In case of implicit unwrapping, the validity of the `future` returned from `then` cannot be established until after the completion of the functor passed into `then`. In such case, the resulting `future` becomes ready with an exception of type `future_error`, with an error code of `future_errc::broken_promise`. ]
  632. ]]
  633. ]
  634. [endsect]
  635. [///////////////////////////////////////////////////]
  636. [section:unwrap Member function `unwrap()` EXTENSION]
  637. template <typename R2>
  638. __unique_future__<R2> __unique_future__<__unique_future__<R2>>::unwrap(); // EXTENSION
  639. template <typename R2>
  640. __shared_future__<R2> __unique_future__<__shared_future__<R2>>::unwrap(); // EXTENSION
  641. [warning These functions are experimental and subject to change in future versions.
  642. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
  643. [note These functions are based on the [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3634.pdf [*N3634 - Improvements to std::future<T> and related APIs]] C++1y proposal by N. Gustafsson, A. Laksberg, H. Sutter, S. Mithani.]
  644. [variablelist
  645. [[Notes:] [Removes the outermost future and returns a future with the associated state been a proxy of the outer future.]]
  646. [[Effects:] [
  647. - Returns a future that becomes ready when the shared state of the outer and inner future is ready. The validity of the future returned from `get()` applied on the outer future cannot be established a priori. If it is not valid, this future is forced to be valid and becomes ready with an exception of type `future_error`, with an error code of `future_errc::broken_promise`.
  648. ]]
  649. [[Returns:] [An object of type future with the associated state been a proxy of outer future.]]
  650. [[Postconditions:] [
  651. - The returned future has `valid() == true`.
  652. ]]
  653. ]
  654. [endsect]
  655. [endsect]
  656. [////////////////////////////////////////////////////]
  657. [section:shared_future `shared_future` class template]
  658. template <typename R>
  659. class shared_future
  660. {
  661. public:
  662. typedef future_state::state state; // EXTENSION
  663. typedef R value_type; // EXTENSION
  664. shared_future() noexcept;
  665. ~shared_future();
  666. // copy support
  667. shared_future(shared_future const& other);
  668. shared_future& operator=(shared_future const& other);
  669. // move support
  670. shared_future(shared_future && other) noexcept;
  671. shared_future(__unique_future__<R> && other) noexcept;
  672. shared_future& operator=(shared_future && other) noexcept;
  673. shared_future& operator=(__unique_future__<R> && other) noexcept;
  674. // factories
  675. template<typename F>
  676. __unique_future__<typename boost::result_of<F(shared_future)>::type>
  677. then(F&& func) const; // EXTENSION
  678. template<typename S, typename F>
  679. __unique_future__<typename boost::result_of<F(shared_future)>::type>
  680. then(S& scheduler, F&& func) const; // EXTENSION
  681. template<typename F>
  682. __unique_future__<typename boost::result_of<F(shared_future)>::type>
  683. then(launch policy, F&& func) const; // EXTENSION
  684. void swap(shared_future& other);
  685. // retrieving the value
  686. see below get() const;
  687. exception_ptr get_exception_ptr(); // EXTENSION
  688. // functions to check state, and wait for ready
  689. bool valid() const noexcept;
  690. bool is_ready() const noexcept; // EXTENSION
  691. bool has_exception() const noexcept; // EXTENSION
  692. bool has_value() const noexcept; // EXTENSION
  693. // waiting for the result to be ready
  694. void wait() const;
  695. template <class Rep, class Period>
  696. future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
  697. template <class Clock, class Duration>
  698. future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
  699. #if defined BOOST_THREAD_USES_DATE_TIME || defined BOOST_THREAD_DONT_USE_CHRONO
  700. template<typename Duration>
  701. bool timed_wait(Duration const& rel_time) const; // DEPRECATED SINCE V3.0.0
  702. bool timed_wait_until(boost::system_time const& abs_time) const; // DEPRECATED SINCE V3.0.0
  703. #endif
  704. state get_state() const noexcept; // EXTENSION
  705. };
  706. [///////////////////////////////////////////////]
  707. [section:default_constructor Default Constructor]
  708. shared_future();
  709. [variablelist
  710. [[Effects:] [Constructs an uninitialized shared_future.]]
  711. [[Postconditions:] [[shared_future_is_ready_link `this->is_ready`] returns `false`. [shared_future_get_state_link
  712. `this->get_state()`] returns __uninitialized__.]]
  713. [[Throws:] [Nothing.]]
  714. ]
  715. [endsect]
  716. [///////////////////////////////////]
  717. [section:get Member function `get()`]
  718. const R& get() const;
  719. R& get() const;
  720. void get() const;
  721. [variablelist
  722. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready as-if by a call to
  723. __shared_future_wait__, and returns a `const` reference to the result.]]
  724. [[Returns:] [
  725. - `shared_future<R&>::get()` return the stored reference.
  726. - `shared_future<void>::get()`, there is no return value.
  727. - `shared_future<R>::get()` returns a `const` reference to the value stored in the shared state.
  728. ]]
  729. [[Throws:] [
  730. - __future_uninitialized__ if `*this` is not associated with a shared state.
  731. - __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  732. ]]
  733. [[Notes:] [`get()` is an ['interruption point].]]
  734. ]
  735. [endsect]
  736. [/////////////////////////////////////]
  737. [section:wait Member function `wait()`]
  738. void wait() const;
  739. [variablelist
  740. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready. If the result is not ready on
  741. entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
  742. [[Throws:] [
  743. - __future_uninitialized__ if `*this` is not associated with a shared state.
  744. - __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  745. - Any exception thrown by the
  746. ['wait callback] if such a callback is called.]]
  747. [[Postconditions:] [[shared_future_is_ready_link `this->is_ready()`] returns `true`. [shared_future_get_state_link
  748. `this->get_state()`] returns __ready__.]]
  749. [[Notes:] [`wait()` is an ['interruption point].]]
  750. ]
  751. [endsect]
  752. [//////////////////////////////////////////////////////////]
  753. [section:timed_wait_duration Member function `timed_wait()`]
  754. template<typename Duration>
  755. bool timed_wait(Duration const& wait_duration);
  756. [variablelist
  757. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time specified by
  758. `wait_duration` has elapsed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is
  759. invoked prior to waiting.]]
  760. [[Returns:] [`true` if `*this` is associated with a shared state, and that result is ready before the specified time has
  761. elapsed, `false` otherwise.]]
  762. [[Throws:] [
  763. - __future_uninitialized__ if `*this` is not associated with a shared state.
  764. - __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  765. - Any exception thrown by the ['wait callback] if such a callback is called.]]
  766. [[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and
  767. [shared_future_get_state_link `this->get_state()`] returns __ready__.]]
  768. [[Notes:] [`timed_wait()` is an ['interruption point]. `Duration` must be a type that meets the Boost.DateTime time duration requirements.]]
  769. ]
  770. [endsect]
  771. [//////////////////////////////////////////////////////////]
  772. [section:timed_wait_absolute Member function `timed_wait()`]
  773. bool timed_wait(boost::system_time const& wait_timeout);
  774. [variablelist
  775. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time point specified by
  776. `wait_timeout` has passed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked
  777. prior to waiting.]]
  778. [[Returns:] [`true` if `*this` is associated with a shared state, and that result is ready before the specified time has
  779. passed, `false` otherwise.]]
  780. [[Throws:] [
  781. - __future_uninitialized__ if `*this` is not associated with a shared state.
  782. - __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  783. - Any exception thrown by the ['wait callback] if such a callback is called.]]
  784. [[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and
  785. [shared_future_get_state_link `this->get_state()`] returns __ready__.]]
  786. [[Notes:] [`timed_wait()` is an ['interruption point].]]
  787. ]
  788. [endsect]
  789. [/////////////////////////////////////////////]
  790. [section:wait_for Member function `wait_for()`]
  791. template <class Rep, class Period>
  792. future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
  793. [variablelist
  794. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time specified by
  795. `wait_duration` has elapsed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is
  796. invoked prior to waiting.]]
  797. [[Returns:] [
  798. - `future_status::deferred` if the shared state contains a deferred function. (Not implemented yet)
  799. - `future_status::ready` if the shared state is ready.
  800. - `future_status::timeout` if the function is returning because the relative timeout specified by `rel_time` has expired.
  801. ]]
  802. [[Throws:] [
  803. - __future_uninitialized__ if `*this` is not associated with a shared state.
  804. - __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  805. - Any exception thrown by the ['wait callback] if such a callback is called.]]
  806. [[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and
  807. [shared_future_get_state_link `this->get_state()`] returns __ready__.]]
  808. [[Notes:] [`timed_wait()` is an ['interruption point]. `Duration` must be a type that meets the Boost.DateTime time duration requirements.]]
  809. ]
  810. [endsect]
  811. [/////////////////////////////////////////////////]
  812. [section:wait_until Member function `wait_until()`]
  813. template <class Clock, class Duration>
  814. future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
  815. [variablelist
  816. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time point specified by
  817. `wait_timeout` has passed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked
  818. prior to waiting.]]
  819. [[Returns:] [
  820. - `future_status::deferred` if the shared state contains a deferred function. (Not implemented yet)
  821. - `future_status::ready` if the shared state is ready.
  822. - `future_status::timeout` if the function is returning because the absolute timeout specified by `absl_time` has reached.
  823. ]]
  824. [[Throws:] [
  825. - __future_uninitialized__ if `*this` is not associated with a shared state.
  826. - __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
  827. - Any exception thrown by the ['wait callback] if such a callback is called.
  828. ]]
  829. [[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and
  830. [shared_future_get_state_link `this->get_state()`] returns __ready__.]]
  831. [[Notes:] [`timed_wait()` is an ['interruption point].]]
  832. ]
  833. [endsect]
  834. [///////////////////////////////////////]
  835. [section:valid Member function `valid()`]
  836. bool valid() const noexcept;
  837. [variablelist
  838. [[Returns:] [`true` if `*this` is associated with a shared state, `false`
  839. otherwise.]]
  840. [[Throws:] [Nothing.]]
  841. ]
  842. [endsect]
  843. [///////////////////////////////////////////////////////]
  844. [section:is_ready Member function `is_ready()` EXTENSION]
  845. bool is_ready() const;
  846. [variablelist
  847. [[Returns:] [`true` if `*this` is associated with a shared state, and that result is ready for retrieval, `false`
  848. otherwise.]]
  849. [[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
  850. ]
  851. [endsect]
  852. [/////////////////////////////////////////////////////////]
  853. [section:has_value Member function `has_value()` EXTENSION]
  854. bool has_value() const;
  855. [variablelist
  856. [[Returns:] [`true` if `*this` is associated with a shared state, that result is ready for retrieval, and the result is a
  857. stored value, `false` otherwise.]]
  858. [[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
  859. ]
  860. [endsect]
  861. [/////////////////////////////////////////////////////////////////]
  862. [section:has_exception Member function `has_exception()` EXTENSION]
  863. bool has_exception() const;
  864. [variablelist
  865. [[Returns:] [`true` if `*this` is associated with a shared state, that result is ready for retrieval, and the result is a
  866. stored exception, `false` otherwise.]]
  867. [[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
  868. ]
  869. [endsect]
  870. [/////////////////////////////////////////////////////////////////]
  871. [section:get_exception_ptr Member function `get_exception_ptr()` EXTENSION]
  872. exception_ptr get_exception_ptr();
  873. [variablelist
  874. [[Effects:] [If `*this` is associated with a shared state, waits until the result is ready. If the result is not ready on
  875. entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
  876. [[Returns:] [an exception_ptr, storing or not an exception.]]
  877. [[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
  878. ]
  879. [endsect]
  880. [/////////////////////////////////////////////////////////]
  881. [section:get_state Member function `get_state()` EXTENSION]
  882. future_state::state get_state();
  883. [variablelist
  884. [[Effects:] [Determine the state of the shared state associated with `*this`, if any.]]
  885. [[Returns:] [__uninitialized__ if `*this` is not associated with a shared state. __ready__ if the shared state
  886. associated with `*this` is ready for retrieval, __waiting__ otherwise.]]
  887. [[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
  888. ]
  889. [endsect]
  890. [///////////////////////////////////////////////]
  891. [section:then Member function `then()` EXTENSION]
  892. template<typename F>
  893. __unique_future__<typename boost::result_of<F(shared_future)>::type>
  894. then(F&& func) const; // EXTENSION
  895. template<typename Ex, typename F>
  896. __unique_future__<typename boost::result_of<F(shared_future)>::type>
  897. then(Ex& executor, F&& func) const; // EXTENSION
  898. template<typename F>
  899. __unique_future__<typename boost::result_of<F(shared_future)>::type>
  900. then(launch policy, F&& func) const; // EXTENSION
  901. [warning These functions are experimental and subject to change in future versions.
  902. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
  903. [note These functions are based on the [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3634.pdf [*N3634 - Improvements to std::future<T> and related APIs]] C++1y proposal by N. Gustafsson, A. Laksberg, H. Sutter, S. Mithani.]
  904. [variablelist
  905. [[Notes:] [The three functions differ only by input parameters. The first only takes a callable object which accepts a
  906. shared_future object as a parameter. The second function takes an executor as the first parameter and a callable object as
  907. the second parameter. The third function takes a launch policy as the first parameter and a callable object as the
  908. second parameter.]]
  909. [[Requires:] [`INVOKE(DECAY_COPY (std::forward<F>(func)), *this)` shall be a valid expression.]]
  910. [[Effects:] [
  911. All the functions create a shared state that is associated with the returned future object. Additionally,
  912. - When the object's shared state is ready, the continuation
  913. `INVOKE(DECAY_COPY(std::forward<F>(func)), *this)` is called depending on the overload (see below) with the call to DECAY_COPY() being evaluated in the thread that called then.
  914. - Any value returned from the continuation is stored as the result in the shared state of the resulting `future`.
  915. Any exception propagated from the execution of the continuation is stored as the exceptional result in the shared state of the resulting `future`.
  916. The continuation launches according to the specified policy or executor or noting.
  917. - When the launch policy is `launch::none` the continuation is called on an unspecified thread of execution.
  918. - When the launch policy is `launch::async` the continuation is called on a new thread of execution.
  919. - When the launch policy is `launch::deferred` the continuation is called on demand.
  920. - When the launch policy is `launch::executor` the continuation is called on one of the thread of execution of the executor.
  921. - When the launch policy is `launch::inherit` the continuation inherits the parent's launch policy or executor.
  922. - When the executor or launch policy is not provided (first overload) is if as if launch::none was specified.
  923. - When the executor is provided (second overload) the continuation is called on one of the thread of execution of the executor.
  924. - If the parent has a policy of `launch::deferred` and the continuation does not have a specified launch policy
  925. executor, then the parent is filled by immediately calling `.wait()`, and the policy of the antecedent is
  926. `launch::deferred`.
  927. ]]
  928. [[Returns:] [An object of type `__unique_future__<typename boost::result_of<F(shared_future)>` that refers to the shared state created by the continuation.]]
  929. [[Notes:] [
  930. - Note that nested futures are not implicitly unwrapped yet. This could be subject to change in future versions.
  931. - The returned futures behave as the ones returned from boost::async, the destructor of the future object returned from then will block. This could be subject to change in future versions.
  932. ]]
  933. [[Postconditions:] [
  934. - The future object is moved to the parameter of the continuation function .
  935. - `valid() == true` on original `shared_future`; `valid() == true` on the `future` returned from then.
  936. [/- In case of implicit unwrapping, the validity of the `future` returned from `then` cannot be established until after the completion of the functor passed into `then`. In such case, the resulting `future` becomes ready with an exception of type `future_error`, with an error code of `future_errc::broken_promise`. ]
  937. ]]
  938. ]
  939. [endsect]
  940. [endsect]
  941. [////////////////////////////////////////]
  942. [section:promise `promise` class template]
  943. template <typename R>
  944. class promise
  945. {
  946. public:
  947. typedef R value_type; // EXTENSION
  948. promise();
  949. template <class Allocator>
  950. promise(allocator_arg_t, Allocator a);
  951. promise & operator=(promise const& rhs) = delete;
  952. promise(promise const& rhs) = delete;
  953. ~promise();
  954. // Move support
  955. promise(promise && rhs) noexcept;;
  956. promise & operator=(promise&& rhs) noexcept;;
  957. void swap(promise& other) noexcept;
  958. // Result retrieval
  959. __unique_future__<R> get_future();
  960. // Set the value
  961. void set_value(see below);
  962. void set_exception(boost::exception_ptr e);
  963. template <typename E>
  964. void set_exception(E e); // EXTENSION
  965. // setting the result with deferred notification
  966. void set_value_at_thread_exit(see below);
  967. void set_exception_at_thread_exit(exception_ptr p);
  968. template <typename E>
  969. void set_exception_at_thread_exit(E p); // EXTENSION
  970. template<typename F>
  971. void set_wait_callback(F f); // EXTENSION
  972. void set_value_deferred(see below); // EXTENSION
  973. void set_exception_deferred(exception_ptr p); // EXTENSION
  974. template <typename E>
  975. void set_exception_deferred(E e); // EXTENSION
  976. void notify_deferred(); // EXTENSION
  977. };
  978. [///////////////////////////////////////////////]
  979. [section:default_constructor Default Constructor]
  980. promise();
  981. [variablelist
  982. [[Effects:] [Constructs a new __promise__ with no associated result.]]
  983. [[Throws:] [Nothing.]]
  984. ]
  985. [endsect]
  986. [///////////////////////////////////////////////]
  987. [section:alloc_constructor Allocator Constructor]
  988. template <class Allocator>
  989. promise(allocator_arg_t, Allocator a);
  990. [variablelist
  991. [[Effects:] [Constructs a new __promise__ with no associated result using the allocator `a`.]]
  992. [[Throws:] [Nothing.]]
  993. [[Notes:] [Available only if BOOST_THREAD_FUTURE_USES_ALLOCATORS is defined.]]
  994. ]
  995. [endsect]
  996. [/////////////////////////////////////////]
  997. [section:move_constructor Move Constructor]
  998. promise(promise && other);
  999. [variablelist
  1000. [[Effects:] [Constructs a new __promise__, and transfers ownership of the result associated with `other` to `*this`, leaving `other`
  1001. with no associated result.]]
  1002. [[Throws:] [Nothing.]]
  1003. [[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
  1004. ]
  1005. [endsect]
  1006. [////////////////////////////////////////////////]
  1007. [section:move_assignment Move Assignment Operator]
  1008. promise& operator=(promise && other);
  1009. [variablelist
  1010. [[Effects:] [Transfers ownership of the result associated with `other` to `*this`, leaving `other` with no associated result. If there
  1011. was already a result associated with `*this`, and that result was not ['ready], sets any futures associated with that result to
  1012. ['ready] with a __broken_promise__ exception as the result. ]]
  1013. [[Throws:] [Nothing.]]
  1014. [[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
  1015. ]
  1016. [endsect]
  1017. [/////////////////////////////]
  1018. [section:destructor Destructor]
  1019. ~promise();
  1020. [variablelist
  1021. [[Effects:] [Destroys `*this`. If there was a result associated with `*this`, and that result is not ['ready], sets any futures
  1022. associated with that task to ['ready] with a __broken_promise__ exception as the result.]]
  1023. [[Throws:] [Nothing.]]
  1024. ]
  1025. [endsect]
  1026. [/////////////////////////////////////////////////]
  1027. [section:get_future Member Function `get_future()`]
  1028. __unique_future__<R> get_future();
  1029. [variablelist
  1030. [[Effects:] [If `*this` was not associated with a result, allocate storage for a new shared state and associate it with
  1031. `*this`. Returns a __unique_future__ associated with the result associated with `*this`. ]]
  1032. [[Throws:] [__future_already_retrieved__ if the future associated with the task has already been retrieved. `std::bad_alloc` if any
  1033. memory necessary could not be allocated.]]
  1034. ]
  1035. [endsect]
  1036. [///////////////////////////////////////////////]
  1037. [section:set_value Member Function `set_value()`]
  1038. void set_value(R&& r);
  1039. void set_value(const R& r);
  1040. void promise<R&>::set_value(R& r);
  1041. void promise<void>::set_value();
  1042. [variablelist
  1043. [[Effects:] [
  1044. - If BOOST_THREAD_PROVIDES_PROMISE_LAZY is defined and if `*this` was not associated with a result, allocate storage for a new shared state and associate it with `*this`.
  1045. - Store the value `r` in the shared state associated with `*this`. Any threads blocked waiting for the asynchronous
  1046. result are woken.
  1047. ]]
  1048. [[Postconditions:] [All futures waiting on the shared state are ['ready] and __unique_future_has_value__ or
  1049. __shared_future_has_value__ for those futures shall return `true`.]]
  1050. [[Throws:] [
  1051. - __promise_already_satisfied__ if the result associated with `*this` is already ['ready].
  1052. - __broken_promise__ if `*this` has no shared state.
  1053. - `std::bad_alloc` if the memory required for storage of the result cannot be allocated.
  1054. - Any exception thrown by the copy or move-constructor of `R`.]]
  1055. ]
  1056. [endsect]
  1057. [///////////////////////////////////////////////////////]
  1058. [section:set_exception Member Function `set_exception()`]
  1059. void set_exception(boost::exception_ptr e);
  1060. template <typename E>
  1061. void set_exception(E e); // EXTENSION
  1062. [variablelist
  1063. [[Effects:] [
  1064. - If BOOST_THREAD_PROVIDES_PROMISE_LAZY is defined and if `*this` was not associated with a result, allocate storage for a new shared state and associate it with
  1065. `*this`.
  1066. - Store the exception `e` in the shared state associated with `*this`. Any threads blocked waiting for the asynchronous
  1067. result are woken.]]
  1068. [[Postconditions:] [All futures waiting on the shared state are ['ready] and __unique_future_has_exception__ or
  1069. __shared_future_has_exception__ for those futures shall return `true`.]]
  1070. [[Throws:] [
  1071. - __promise_already_satisfied__ if the result associated with `*this` is already ['ready].
  1072. - __broken_promise__ if `*this` has no shared state.
  1073. - `std::bad_alloc` if the memory required for storage of the result cannot be allocated.
  1074. ]]
  1075. ]
  1076. [endsect]
  1077. [/////////////////////////////////////////////////////////////////////////////]
  1078. [section:set_value_at_thread_exit Member Function `set_value_at_thread_exit()`]
  1079. void set_value_at_thread_exit(R&& r);
  1080. void set_value_at_thread_exit(const R& r);
  1081. void promise<R&>::set_value_at_thread_exit(R& r);
  1082. void promise<void>::set_value_at_thread_exit();
  1083. [variablelist
  1084. [[Effects:] [
  1085. Stores the value r in the shared state without making that state ready immediately.
  1086. Schedules that state to be made ready when the current thread exits, after all objects of thread storage duration
  1087. associated with the current thread have been destroyed.]]
  1088. [[Postconditions:] [the result associated with `*this` is set as deferred]]
  1089. [[Throws:] [
  1090. - __promise_already_satisfied__ if the result associated with `*this` is already ['ready] or deferred.
  1091. - __broken_promise__ if `*this` has no shared state.
  1092. - `std::bad_alloc` if the memory required for storage of the result cannot be allocated.
  1093. - Any exception thrown by the copy or move-constructor of `R`.
  1094. ]]
  1095. ]
  1096. [endsect]
  1097. [/////////////////////////////////////////////////////////////////////////////////////]
  1098. [section:set_exception_at_thread_exit Member Function `set_exception_at_thread_exit()`]
  1099. void set_exception_at_thread_exit(boost::exception_ptr e);
  1100. template <typename E>
  1101. void set_exception_at_thread_exit(E p); // EXTENSION
  1102. [variablelist
  1103. [[Effects:] [
  1104. Stores the exception pointer p in the shared state without making that state ready immediately.
  1105. Schedules that state to be made ready when the current thread exits, after all objects of thread storage duration
  1106. associated with the current thread have been destroyed.]]
  1107. [[Postconditions:] [the result associated with `*this` is set as deferred]]
  1108. [[Throws:] [
  1109. - __promise_already_satisfied__ if the result associated with `*this` is already ['ready] or deferred.
  1110. - __broken_promise__ if `*this` has no shared state.
  1111. - `std::bad_alloc` if the memory required for storage of the result cannot be allocated.
  1112. ]]
  1113. ]
  1114. [endsect]
  1115. [/////////////////////////////////////////////////////////////////////////]
  1116. [section:set_wait_callback Member Function `set_wait_callback()` EXTENSION]
  1117. template<typename F>
  1118. void set_wait_callback(F f);
  1119. [variablelist
  1120. [[Preconditions:] [The expression `f(t)` where `t` is a lvalue of type __promise__ shall be well-formed. Invoking a copy of
  1121. `f` shall have the same effect as invoking `f`]]
  1122. [[Effects:] [Store a copy of `f` with the shared state associated with `*this` as a ['wait callback]. This will replace any
  1123. existing wait callback store alongside that result. If a thread subsequently calls one of the wait functions on a __unique_future__
  1124. or __shared_future__ associated with this result, and the result is not ['ready], `f(*this)` shall be invoked.]]
  1125. [[Throws:] [`std::bad_alloc` if memory cannot be allocated for the required storage.]]
  1126. ]
  1127. [endsect]
  1128. [///////////////////////////////////////////////]
  1129. [section:set_value Member Function `set_value_deferred()` EXTENSION]
  1130. void set_value_deferred(R&& r);
  1131. void set_value_deferred(const R& r);
  1132. void promise<R&>:: set_value_deferred(R& r);
  1133. void promise<void>:: set_value_deferred();
  1134. [variablelist
  1135. [[Effects:] [
  1136. - If BOOST_THREAD_PROVIDES_PROMISE_LAZY is defined and if `*this` was not associated with a result, allocate storage for a new shared state and associate it with `*this`.
  1137. - Stores the value `r` in the shared state without making that state ready immediately. Threads blocked waiting for the asynchronous result are not woken. They will be woken only when `notify_deferred` is called.
  1138. ]]
  1139. [[Postconditions:] [the result associated with `*this` is set as deferred]]
  1140. [[Throws:] [
  1141. - __promise_already_satisfied__ if the result associated with `*this` is already ['ready] or deferred.
  1142. - __broken_promise__ if `*this` has no shared state.
  1143. - `std::bad_alloc` if the memory required for storage of the result cannot be allocated.
  1144. - Any exception thrown by the copy or move-constructor of `R`.]]
  1145. ]
  1146. [endsect]
  1147. [///////////////////////////////////////////////////////]
  1148. [section:set_exception Member Function `set_exception_deferred()` EXTENSION]
  1149. void set_exception_deferred(boost::exception_ptr e);
  1150. template <typename E>
  1151. void set_exception_deferred(E e); // EXTENSION
  1152. [variablelist
  1153. [[Effects:] [
  1154. - If BOOST_THREAD_PROVIDES_PROMISE_LAZY is defined and if `*this` was not associated with a result, allocate storage for a new shared state and associate it with `*this`.
  1155. - Store the exception `e` in the shared state associated with `*this`without making that state ready immediately. Threads blocked waiting for the asynchronous result are not woken. They will be woken only when `notify_deferred` is called.]]
  1156. [[Postconditions:] [the result associated with `*this` is set as deferred]]
  1157. [[Throws:] [
  1158. - __promise_already_satisfied__ if the result associated with `*this` is already ['ready] or deferred.
  1159. - __broken_promise__ if `*this` has no shared state.
  1160. - `std::bad_alloc` if the memory required for storage of the result cannot be allocated.
  1161. ]]
  1162. ]
  1163. [endsect]
  1164. [///////////////////////////////////////////////]
  1165. [section:set_value Member Function `notify_deferred()` EXTENSION]
  1166. [variablelist
  1167. [[Effects:] [
  1168. Any threads blocked waiting for the asynchronous result are woken.
  1169. ]]
  1170. [[Postconditions:] [All futures waiting on the shared state are ['ready] and __unique_future_has_value__ or
  1171. __shared_future_has_value__ for those futures shall return `true`.]]
  1172. [[Postconditions:] [the result associated with `*this` is ready.]]
  1173. ]
  1174. [endsect]
  1175. [endsect]
  1176. [////////////////////////////////////////////////////]
  1177. [section:packaged_task `packaged_task` class template]
  1178. template<typename S>
  1179. class packaged_task;
  1180. template<typename R
  1181. , class... ArgTypes
  1182. >
  1183. class packaged_task<R(ArgTypes)>
  1184. {
  1185. public:
  1186. packaged_task(packaged_task const&) = delete;
  1187. packaged_task& operator=(packaged_task const&) = delete;
  1188. // construction and destruction
  1189. packaged_task() noexcept;
  1190. explicit packaged_task(R(*f)(ArgTypes...));
  1191. template <class F>
  1192. explicit packaged_task(F&& f);
  1193. template <class Allocator>
  1194. packaged_task(allocator_arg_t, Allocator a, R(*f)(ArgTypes...));
  1195. template <class F, class Allocator>
  1196. packaged_task(allocator_arg_t, Allocator a, F&& f);
  1197. ~packaged_task()
  1198. {}
  1199. // move support
  1200. packaged_task(packaged_task&& other) noexcept;
  1201. packaged_task& operator=(packaged_task&& other) noexcept;
  1202. void swap(packaged_task& other) noexcept;
  1203. bool valid() const noexcept;
  1204. // result retrieval
  1205. __unique_future__<R> get_future();
  1206. // execution
  1207. void operator()(ArgTypes... );
  1208. void make_ready_at_thread_exit(ArgTypes...);
  1209. void reset();
  1210. template<typename F>
  1211. void set_wait_callback(F f); // EXTENSION
  1212. };
  1213. [/////////////////////////////////////////]
  1214. [section:task_constructor Task Constructor]
  1215. packaged_task(R(*f)(ArgTypes...));
  1216. template<typename F>
  1217. packaged_task(F&&f);
  1218. [variablelist
  1219. [[Preconditions:] [`f()` is a valid expression with a return type convertible to `R`. Invoking a copy of `f` must behave the same
  1220. as invoking `f`.]]
  1221. [[Effects:] [Constructs a new __packaged_task__ with `boost::forward<F>(f)` stored as the associated task.]]
  1222. [[Throws:] [
  1223. - Any exceptions thrown by the copy (or move) constructor of `f`.
  1224. - `std::bad_alloc` if memory for the internal data structures could not be allocated.
  1225. ]]
  1226. [[Notes:] [The R(*f)(ArgTypes...)) overload to allow passing a function without needing to use `&`.]]
  1227. [[Remark:] [This constructor doesn't participate in overload resolution if decay<F>::type is the same type as boost::packaged_task<R>.]]
  1228. ]
  1229. [endsect]
  1230. [///////////////////////////////////////////////]
  1231. [section:alloc_constructor Allocator Constructor]
  1232. template <class Allocator>
  1233. packaged_task(allocator_arg_t, Allocator a, R(*f)(ArgTypes...));
  1234. template <class F, class Allocator>
  1235. packaged_task(allocator_arg_t, Allocator a, F&& f);
  1236. [variablelist
  1237. [[Preconditions:] [`f()` is a valid expression with a return type convertible to `R`. Invoking a copy of `f` shall behave the same
  1238. as invoking `f`.]]
  1239. [[Effects:] [Constructs a new __packaged_task with `boost::forward<F>(f)` stored as the associated task using the allocator `a`.]]
  1240. [[Throws:] [Any exceptions thrown by the copy (or move) constructor of `f`. `std::bad_alloc` if memory for the internal data
  1241. structures could not be allocated.]]
  1242. [[Notes:] [Available only if BOOST_THREAD_FUTURE_USES_ALLOCATORS is defined.]]
  1243. [[Notes:] [The R(*f)(ArgTypes...)) overload to allow passing a function without needing to use `&`.]]
  1244. ]
  1245. [endsect]
  1246. [/////////////////////////////////////////]
  1247. [section:move_constructor Move Constructor]
  1248. packaged_task(packaged_task && other);
  1249. [variablelist
  1250. [[Effects:] [Constructs a new __packaged_task__, and transfers ownership of the task associated with `other` to `*this`, leaving `other`
  1251. with no associated task.]]
  1252. [[Throws:] [Nothing.]]
  1253. [[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
  1254. ]
  1255. [endsect]
  1256. [////////////////////////////////////////////////]
  1257. [section:move_assignment Move Assignment Operator]
  1258. packaged_task& operator=(packaged_task && other);
  1259. [variablelist
  1260. [[Effects:] [Transfers ownership of the task associated with `other` to `*this`, leaving `other` with no associated task. If there
  1261. was already a task associated with `*this`, and that task has not been invoked, sets any futures associated with that task to
  1262. ['ready] with a __broken_promise__ exception as the result. ]]
  1263. [[Throws:] [Nothing.]]
  1264. [[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
  1265. ]
  1266. [endsect]
  1267. [/////////////////////////////]
  1268. [section:destructor Destructor]
  1269. ~packaged_task();
  1270. [variablelist
  1271. [[Effects:] [Destroys `*this`. If there was a task associated with `*this`, and that task has not been invoked, sets any futures
  1272. associated with that task to ['ready] with a __broken_promise__ exception as the result.]]
  1273. [[Throws:] [Nothing.]]
  1274. ]
  1275. [endsect]
  1276. [/////////////////////////////////////////////////]
  1277. [section:get_future Member Function `get_future()`]
  1278. __unique_future__<R> get_future();
  1279. [variablelist
  1280. [[Effects:] [Returns a __unique_future__ associated with the result of the task associated with `*this`. ]]
  1281. [[Throws:] [__task_moved__ if ownership of the task associated with `*this` has been moved to another instance of
  1282. __packaged_task__. __future_already_retrieved__ if the future associated with the task has already been retrieved.]]
  1283. ]
  1284. [endsect]
  1285. [////////////////////////////////////////////////////]
  1286. [section:call_operator Member Function `operator()()`]
  1287. void operator()();
  1288. [variablelist
  1289. [[Effects:] [Invoke the task associated with `*this` and store the result in the corresponding future. If the task returns normally,
  1290. the return value is stored as the shared state, otherwise the exception thrown is stored. Any threads blocked waiting for the
  1291. shared state associated with this task are woken.]]
  1292. [[Postconditions:] [All futures waiting on the shared state are ['ready]]]
  1293. [[Throws:] [
  1294. - __task_moved__ if ownership of the task associated with `*this` has been moved to another instance of __packaged_task__.
  1295. - __task_already_started__ if the task has already been invoked.]]
  1296. ]
  1297. [endsect]
  1298. [///////////////////////////////////////////////////////////////////////////////]
  1299. [section:make_ready_at_thread_exit Member Function `make_ready_at_thread_exit()`]
  1300. void make_ready_at_thread_exit(ArgTypes...);
  1301. [variablelist
  1302. [[Effects:] [Invoke the task associated with `*this` and store the result in the corresponding future. If the task returns normally,
  1303. the return value is stored as the shared state, otherwise the exception thrown is stored.
  1304. In either case, this is done without making that state ready immediately.
  1305. Schedules the shared state to be made ready when the current thread exits, after all objects of thread storage
  1306. duration associated with the current thread have been destroyed.]]
  1307. [[Throws:] [
  1308. - __task_moved__ if ownership of the task associated with `*this` has been moved to another instance of __packaged_task__.
  1309. - __task_already_started__ if the task has already been invoked.
  1310. ]]
  1311. ]
  1312. [endsect]
  1313. [///////////////////////////////////////]
  1314. [section:reset Member Function `reset()`]
  1315. void reset();
  1316. [variablelist
  1317. [[Effects:] [Reset the state of the packaged_task so that it can be called again.]]
  1318. [[Throws:] [__task_moved__ if ownership of the task associated with `*this` has been moved to another instance of
  1319. __packaged_task__.]]
  1320. ]
  1321. [endsect]
  1322. [/////////////////////////////////////////////////////////////////////////]
  1323. [section:set_wait_callback Member Function `set_wait_callback()` EXTENSION]
  1324. template<typename F>
  1325. void set_wait_callback(F f);
  1326. [variablelist
  1327. [[Preconditions:] [The expression `f(t)` where `t` is a lvalue of type __packaged_task__ shall be well-formed. Invoking a copy of
  1328. `f` shall have the same effect as invoking `f`]]
  1329. [[Effects:] [Store a copy of `f` with the task associated with `*this` as a ['wait callback]. This will replace any existing wait
  1330. callback store alongside that task. If a thread subsequently calls one of the wait functions on a __unique_future__ or
  1331. __shared_future__ associated with this task, and the result of the task is not ['ready], `f(*this)` shall be invoked.]]
  1332. [[Throws:] [__task_moved__ if ownership of the task associated with `*this` has been moved to another instance of
  1333. __packaged_task__.]]
  1334. ]
  1335. [endsect]
  1336. [endsect]
  1337. [//////////////////////////////////////////////////////]
  1338. [section:decay_copy Non-member function `decay_copy()`]
  1339. template <class T>
  1340. typename decay<T>::type decay_copy(T&& v)
  1341. {
  1342. return boost::forward<T>(v);
  1343. }
  1344. [endsect]
  1345. [///////////////////////////////////////////]
  1346. [section:async Non-member function `async()`]
  1347. The function template async provides a mechanism to launch a function potentially in a new thread and
  1348. provides the result of the function in a future object with which it shares a shared state.
  1349. [heading Non-Variadic variant]
  1350. template <class F>
  1351. __unique_future__<typename result_of<typename decay<F>::type()>::type>
  1352. async(F&& f);
  1353. template <class F>
  1354. __unique_future__<typename result_of<typename decay<F>::type()>::type>
  1355. async(launch policy, F&& f);
  1356. template <class Executor, class F>
  1357. __unique_future__<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
  1358. async(Executor &ex, F&& f, Args&&... args);
  1359. [variablelist
  1360. [[Requires:] [
  1361. ``
  1362. decay_copy(boost::forward<F>(f))()
  1363. ``
  1364. shall be a valid expression.
  1365. ]]
  1366. [[Effects] [
  1367. The first function behaves the same as a call to the second function with a policy argument of
  1368. `launch::async | launch::deferred` and the same arguments for `F`.
  1369. The second and third functions create a shared state that is associated with the returned future object.
  1370. The further behavior of the second function depends on the policy argument as follows (if more than one of these conditions applies, the implementation may choose any of the corresponding policies):
  1371. - if `policy & launch::async` is non-zero - calls `decay_copy(boost::forward<F>(f))()` as if in a new thread of execution represented by a thread object with the calls to `decay_copy()` being evaluated in the thread that called `async`. Any return value is stored as the result in the shared state. Any exception propagated from the execution of `decay_copy(boost::forward<F>(f))()` is stored as the exceptional result in the shared state. The thread object is stored in the shared state and affects the behavior of any asynchronous return objects that reference that state.
  1372. - if `policy & launch::deferred` is non-zero - Stores `decay_copy(boost::forward<F>(f))` in the shared state. This copy of `f` constitute a deferred function. Invocation of the deferred function evaluates `boost::move(g)()` where `g` is the stored value of `decay_copy(boost::forward<F>(f))`. The shared state is not made ready until the function has completed. The first call to a non-timed waiting function on an asynchronous return object referring to this shared state shall invoke the deferred function in the thread that called the waiting function. Once evaluation of `boost::move(g)()` begins, the function is no longer considered deferred. (Note: If this policy is specified together with other policies, such as when using a policy value of `launch::async | launch::deferred`, implementations should defer invocation or the selection of the policy when no more concurrency can be effectively exploited.)
  1373. - if no valid launch policy is provided the behavior is undefined.
  1374. The further behavior of the third function is as follows:
  1375. - The Executor::submit() function is given a function<void ()> which calls `INVOKE (DECAY_COPY
  1376. (std::forward<F>(f)), DECAY_COPY (std::forward<Args>(args))...). The implementation of the executor
  1377. is decided by the programmer.
  1378. ]]
  1379. [[Returns:] [An object of type `__unique_future__<typename result_of<typename decay<F>::type()>::type>` that refers to the shared state created by this call to `async`.]]
  1380. [[Synchronization:] [Regardless of the provided policy argument,
  1381. - the invocation of `async` synchronizes with the invocation of `f`. (Note: This statement applies even when the corresponding future object is moved to another thread.); and
  1382. - the completion of the function `f` is sequenced before the shared state is made ready. (Note: `f` might not be called at all, so its completion might never happen.)
  1383. If the implementation chooses the `launch::async` policy,
  1384. - a call to a non-timed waiting function on an asynchronous return object that shares the shared state created by this async call shall block until the associated thread has completed, as if joined, or else time out;
  1385. - the associated thread completion synchronizes with the return from the first function that successfully detects the ready status of the shared state or with the return from the last function that releases the shared state, whichever happens first.
  1386. ]]
  1387. [[Throws:][`system_error` if policy is `launch::async` and the implementation is unable to start a new thread.
  1388. ]]
  1389. [[Error conditions:] [
  1390. - `resource_unavailable_try_again` - if policy is `launch::async` and the system is unable to start a new thread.
  1391. ]]
  1392. [[Remarks::] [The first signature shall not participate in overload resolution if `decay_t<F> is `boost::
  1393. launch` or `boost::is_executor<F>` is `true_type`.]]
  1394. ]
  1395. [heading Variadic variant]
  1396. template <class F, class... Args>
  1397. __unique_future__<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
  1398. async(F&& f, Args&&... args);
  1399. template <class F, class... Args>
  1400. __unique_future__<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
  1401. async(launch policy, F&& f, Args&&... args);
  1402. template <class Executor, class F, class... Args>
  1403. __unique_future__<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
  1404. async(Executor &ex, F&& f, Args&&... args);
  1405. [warning the variadic prototype is provided only on C++11 compilers supporting rvalue references, variadic templates, decltype and a standard library providing <tuple> (waiting for a boost::tuple that is move aware), and BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK is defined.]
  1406. [variablelist
  1407. [[Requires:] [
  1408. `F` and each `Ti` in `Args` shall satisfy the `MoveConstructible` requirements.
  1409. invoke (decay_copy (boost::forward<F>(f)), decay_copy (boost::forward<Args>(args))...)
  1410. shall be a valid expression.
  1411. ]]
  1412. [[Effects:] [
  1413. - The first function behaves the same as a call to the second function with a policy argument of `launch::async | launch::deferred` and the same arguments for `F` and `Args`.
  1414. - The second function creates a shared state that is associated with the returned future object.
  1415. The further behavior of the second function depends on the policy argument as follows (if more than one of these conditions applies,
  1416. the implementation may choose any of the corresponding policies):
  1417. - if `policy & launch::async` is non-zero - calls `invoke(decay_copy(forward<F>(f)), decay_copy (forward<Args>(args))...)`
  1418. as if in a new thread of execution represented by a thread object with the calls to `decay_copy()` being evaluated in the thread that called `async`.
  1419. Any return value is stored as the result in the shared state.
  1420. Any exception propagated from the execution of `invoke(decay_copy(boost::forward<F>(f)), decay_copy (boost::forward<Args>(args))...)`
  1421. is stored as the exceptional result in the shared state. The thread object is stored in the shared state and
  1422. affects the behavior of any asynchronous return objects that reference that state.
  1423. - if `policy & launch::deferred` is non-zero - Stores `decay_copy(forward<F>(f))` and `decay_copy(forward<Args>(args))...` in the shared state.
  1424. These copies of `f` and `args` constitute a deferred function. Invocation of the deferred function evaluates
  1425. `invoke(move(g), move(xyz))` where `g` is the stored value of `decay_copy(forward<F>(f))` and `xyz` is the stored copy of `decay_copy(forward<Args>(args))...`.
  1426. The shared state is not made ready until the function has completed. The first call to a non-timed waiting function on
  1427. an asynchronous return object referring to this shared state shall invoke the deferred function in the thread that called the waiting function.
  1428. Once evaluation of `invoke(move(g), move(xyz))` begins, the function is no longer considered deferred.
  1429. - if no valid launch policy is provided the behaviour is undefined.
  1430. ]]
  1431. [[Note:] [If this policy is specified together with other policies, such as when using a policy value of `launch::async | launch::deferred`,
  1432. implementations should defer invocation or the selection of the policy when no more concurrency can be effectively exploited.]]
  1433. [[Returns:] [An object of type `__unique_future__<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>`
  1434. that refers to the shared state created by this call to `async`.]]
  1435. [[Synchronization:] [Regardless of the provided policy argument,
  1436. - the invocation of async synchronizes with the invocation of `f`. (Note: This statement applies even when the corresponding future object is moved to another thread.); and
  1437. - the completion of the function `f` is sequenced before the shared state is made ready. (Note: f might not be called at all, so its completion might never happen.)
  1438. If the implementation chooses the `launch::async` policy,
  1439. - a call to a waiting function on an asynchronous return object that shares the shared state created by this async call
  1440. shall block until the associated thread has completed, as if joined, or else time out;
  1441. - the associated thread completion synchronizes with the return from the first function that successfully detects the ready status of the shared state or
  1442. with the return from the last function that releases the shared state, whichever happens first.
  1443. ]]
  1444. [[Throws:] [`system_error` if policy is `launch::async` and the implementation is unable to start a new thread.
  1445. ]]
  1446. [[Error conditions:][
  1447. - `resource_unavailable_try_again` - if policy is `launch::async` and the system is unable to start a new thread.
  1448. ]]
  1449. [[Remarks:] [The first signature shall not participate in overload resolution if decay<F>::type is boost::launch.
  1450. ]]
  1451. ]
  1452. [endsect]
  1453. [/////////////////////////////////////////////////////////////////////]
  1454. [section:wait_for_any Non-member function `wait_for_any()` - EXTENSION]
  1455. template<typename Iterator>
  1456. Iterator wait_for_any(Iterator begin,Iterator end); // EXTENSION
  1457. template<typename F1,typename F2>
  1458. unsigned wait_for_any(F1& f1,F2& f2); // EXTENSION
  1459. template<typename F1,typename F2,typename F3>
  1460. unsigned wait_for_any(F1& f1,F2& f2,F3& f3); // EXTENSION
  1461. template<typename F1,typename F2,typename F3,typename F4>
  1462. unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4); // EXTENSION
  1463. template<typename F1,typename F2,typename F3,typename F4,typename F5>
  1464. unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5); // EXTENSION
  1465. [variablelist
  1466. [[Preconditions:] [The types `Fn` shall be specializations of
  1467. __unique_future__ or __shared_future__, and `Iterator` shall be a
  1468. forward iterator with a `value_type` which is a specialization of
  1469. __unique_future__ or __shared_future__.]]
  1470. [[Effects:] [Waits until at least one of the specified futures is ['ready].]]
  1471. [[Returns:] [The range-based overload returns an `Iterator` identifying the first future in the range that was detected as
  1472. ['ready]. The remaining overloads return the zero-based index of the first future that was detected as ['ready] (first parameter =>
  1473. 0, second parameter => 1, etc.).]]
  1474. [[Throws:] [__thread_interrupted__ if the current thread is interrupted. Any exception thrown by the ['wait callback] associated
  1475. with any of the futures being waited for. `std::bad_alloc` if memory could not be allocated for the internal wait structures.]]
  1476. [[Notes:] [`wait_for_any()` is an ['interruption point].]]
  1477. ]
  1478. [endsect]
  1479. [/////////////////////////////////////////////////////////////////////]
  1480. [section:wait_for_all Non-member function `wait_for_all()` - EXTENSION]
  1481. template<typename Iterator>
  1482. void wait_for_all(Iterator begin,Iterator end); // EXTENSION
  1483. template<typename F1,typename F2>
  1484. void wait_for_all(F1& f1,F2& f2); // EXTENSION
  1485. template<typename F1,typename F2,typename F3>
  1486. void wait_for_all(F1& f1,F2& f2,F3& f3); // EXTENSION
  1487. template<typename F1,typename F2,typename F3,typename F4>
  1488. void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4); // EXTENSION
  1489. template<typename F1,typename F2,typename F3,typename F4,typename F5>
  1490. void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5); // EXTENSION
  1491. [variablelist
  1492. [[Preconditions:] [The types `Fn` shall be specializations of
  1493. __unique_future__ or __shared_future__, and `Iterator` shall be a
  1494. forward iterator with a `value_type` which is a specialization of
  1495. __unique_future__ or __shared_future__.]]
  1496. [[Effects:] [Waits until all of the specified futures are ['ready].]]
  1497. [[Throws:] [Any exceptions thrown by a call to `wait()` on the specified futures.]]
  1498. [[Notes:] [`wait_for_all()` is an ['interruption point].]]
  1499. ]
  1500. [endsect]
  1501. [/////////////////////////////////////////////////////////////////////]
  1502. [section:when_all Non-member function `when_all()` - EXTENSION]
  1503. template <class InputIterator>
  1504. future<std::vector<typename InputIterator::value_type::value_type>>
  1505. when_all(InputIterator first, InputIterator last);
  1506. template <typename... FutTypes>
  1507. future<std::tuple<decay_t<FutTypes>...> when_all(FutTypes&&... futures);
  1508. [variablelist
  1509. [[Requires:] [
  1510. - For the first overload, `InputIterator`'s value type shall be convertible to `future<R>` or `shared_future<R>`.
  1511. All `R` types must be the same. If any of the `future<R>` or `shared_future<R>` objects are in invalid state (i.e. `valid() == false`), the behavior is undefined.
  1512. - For the second overload, `FutTypes` is of type `future<R>` or `shared_future<R>`. The effect of calling `when_all` on a `future` or a `shared_future` object for which `valid() == false` is undefined.
  1513. ]]
  1514. [[Notes:] [
  1515. - There are two variations of `when_all`. The first version takes a pair of `InputIterators`. The second takes any arbitrary number of `future<R0>` and `shared_future<R1>` objects, where `R0` and `R1` need not be the same type.
  1516. - Calling the first signature of `when_all` where `InputIterator` first equals last, returns a future with an empty `vector` that is immediately ready.
  1517. - Calling the second signature of `when_all` with no arguments returns a future<tuple<>> that is immediately ready.
  1518. ]]
  1519. [[Effects:] [
  1520. - If any of the futures supplied to a call to `when_all` refer to deferred tasks that have not started execution, those tasks are executed before the call to `when_all` returns. Once all such tasks have been executed, the call to `when_all` returns immediately.
  1521. - The call to `when_all` does not wait for non-deferred tasks, or deferred tasks that have already started executing elsewhere, to complete before returning.
  1522. - Once all the `future`s/`shared_future`s supplied to the call to `when_all` are ready, the `future`s/`shared_future`s are moved/copied into the associated state of the future returned from the call to `when_all`, preserving the order of the futures supplied to `when_all`.
  1523. - The collection is then stored as the result in a newly created shared state.
  1524. - A new future object that refers to the shared state is created. The exact type of the future is further described below.
  1525. - The `future` returned by `when_all` will not throw an exception when calling `wait()` or `get()`, but the futures held in the output collection may.
  1526. ]]
  1527. [[Returns:] [
  1528. - `future<tuple<>>` if `when_all` is called with zero arguments.
  1529. - `future<vector<future<R>>>` if the input cardinality is unknown at compile and the iterator pair yields `future<R>`. The order of the futures in the output vector will be the same as given by the input iterator.
  1530. - `future<vector<shared_future<R>>>` if the input cardinality is unknown at compile time and the iterator pair yields `shared_future<R>`. The order of the futures in the output vector will be the same as given by the input iterator.
  1531. - `future<tuple<decay_t<FutTypes>...>>` if inputs are fixed in number.
  1532. ]]
  1533. [[Postconditions:] [
  1534. - All input futures valid() == false.
  1535. - All input shared future valid() == true.
  1536. - valid() == true.
  1537. ]]
  1538. ]
  1539. [endsect]
  1540. [/////////////////////////////////////////////////////////////////////]
  1541. [section:when_any Non-member function `when_any()` - EXTENSION]
  1542. template <class InputIterator>
  1543. future<std::vector<typename InputIterator::value_type::value_type>>
  1544. when_any(InputIterator first, InputIterator last);
  1545. template <typename... FutTypes>
  1546. future<std::tuple<decay_t<FutTypes>...>
  1547. when_any(FutTypes&&... futures);
  1548. [variablelist
  1549. [[Requires:] [
  1550. - For the first overload, `InputIterator`'s value type shall be convertible to `future<R>` or `shared_future<R>`. All `R` types must be the same. If any of the `future<R>` or `shared_future<R>` objects are in invalid state (i.e. `valid() == false`), the behavior is undefined.
  1551. - For the second overload, `FutTypes` is of type `future<R>` or `shared_future<R>`. The effect of calling `when_any` on a `future` or a `shared_future` object for which `valid() == false is undefined`.
  1552. ]]
  1553. [[Notes:] [
  1554. - There are two variations of `when_any `. The first version takes a pair of `InputIterators`. The second takes any arbitrary number of `future<R0>` and `shared_future<R1>` objects, where `R0` and `R1` need not be the same type.
  1555. - Calling the first signature of `when_any ` where `InputIterator` first equals last, returns a future with an empty `vector` that is immediately ready.
  1556. - Calling the second signature of `when_any` with no arguments returns a future<tuple<>> that is immediately ready.
  1557. ]]
  1558. [[Effects:] [
  1559. - Each of the futures supplied to `when_any` is checked in the order supplied. If a given future is ready, then no further futures are checked, and the call to `when_any` returns immediately. If a given future refers to a deferred task that has not yet started execution, then no further futures are checked, that task is executed, and the call to `when_any` then returns immediately.
  1560. - The call to `when_any` does not wait for non-deferred tasks, or deferred tasks that have already started executing elsewhere, to complete before returning.
  1561. - Once at least one of the futures supplied to the call to `when_any` are ready, the futures are moved into the associated state of the future returned from the call to `when_any`, preserving the order of the futures supplied to `when_any`. That future is then ready.
  1562. - The collection is then stored as the result in a newly created shared state.
  1563. - A new future object that refers to the shared state is created. The exact type of the future is further described below.
  1564. - The future returned by `when_any` will not throw an exception when calling `wait()` or `get()`, but the futures held in the output collection may.
  1565. ]]
  1566. [[Returns:] [
  1567. - `future<tuple<>>` if `when_any ` is called with zero arguments.
  1568. - `future<vector<future<R>>>` if the input cardinality is unknown at compile and the iterator pair yields `future<R>`. The order of the futures in the output vector will be the same as given by the input iterator.
  1569. - `future<vector<shared_future<R>>>` if the input cardinality is unknown at compile time and the iterator pair yields `shared_future<R>`. The order of the futures in the output vector will be the same as given by the input iterator.
  1570. - `future<tuple<decat_t<FutTypes>...>>` if inputs are fixed in number.
  1571. ]]
  1572. [[Postconditions:] [
  1573. - All input futures valid() == false.
  1574. - All input shared_futures valid() == true.
  1575. - valid() == true.
  1576. ]]
  1577. ]
  1578. [endsect]
  1579. [/////////////////////////////////////////////////////////////////////////////]
  1580. [section:make_ready_future Non-member function `make_ready_future()` EXTENSION]
  1581. template <typename T>
  1582. future<V> make_ready_future(T&& value); // EXTENSION
  1583. future<void> make_ready_future(); // EXTENSION
  1584. template <typename T>
  1585. future<T> make_ready_future(exception_ptr ex); // DEPRECATED
  1586. template <typename T, typename E>
  1587. future<T> make_ready_future(E ex); // DEPRECATED
  1588. [variablelist
  1589. [[Remark:][
  1590. where `V` is determined as follows: Let `U` be `decay_t<T>`. Then `V` is `X&`
  1591. if `U` equals `reference_wrapper<X>`, otherwise `V` is `U`.
  1592. ]]
  1593. [[Effects:] [
  1594. - value prototype: The value that is passed into the function is moved to the shared state of the returned future if it is an rvalue.
  1595. Otherwise the value is copied to the shared state of the returned future.
  1596. - exception: The exception that is passed into the function is copied to the shared state of the returned future.
  1597. .]]
  1598. [[Returns:] [
  1599. - a ready future with the value set with `value`
  1600. - a ready future with the exception set with `ex`
  1601. - a ready future<void> with the value set (void).
  1602. ]]
  1603. [[Postcondition:] [
  1604. - Returned future, valid() == true
  1605. - Returned future, is_ready() = true
  1606. - Returned future, has_value() = true or has_exception() depending on the prototype.
  1607. ]]
  1608. ]
  1609. [endsect]
  1610. [/////////////////////////////////////////////////////////////////////////////]
  1611. [section:make_exceptional_future Non-member function `make_exceptional_future()` EXTENSION]
  1612. exceptional_ptr make_exceptional_future(exception_ptr ex); // EXTENSION
  1613. template <typename E>
  1614. exceptional_ptr make_exceptional_future(E ex); // EXTENSION
  1615. exceptional_ptr make_exceptional_future(); // EXTENSION
  1616. [variablelist
  1617. [[Effects:] [
  1618. The exception that is passed in to the function or the current exception if no parameter is given is moved into the returned `exceptional_ptr` if it is an rvalue. Otherwise the exception is copied into the returned `exceptional_ptr`.
  1619. ]]
  1620. [[Returns:] [
  1621. An exceptional_ptr instance implicitly convertible to a future<T>
  1622. ]]
  1623. ]
  1624. [endsect]
  1625. [//////////////////////////////////////////////////////////////////]
  1626. [section:make_future Non-member function `make_future()` DEPRECATED]
  1627. template <typename T>
  1628. future<typename decay<T>::type> make_future(T&& value); // DEPRECATED
  1629. future<void> make_future(); // DEPRECATED
  1630. [variablelist
  1631. [[Effects:] [
  1632. The value that is passed into the function is moved to the shared state of the returned function if it is an rvalue.
  1633. Otherwise the value is copied to the shared state of the returned function.
  1634. .]]
  1635. [[Returns:] [
  1636. - future<T>, if function is given a value of type T
  1637. - future<void>, if the function is not given any inputs.
  1638. ]]
  1639. [[Postcondition:] [
  1640. - Returned future<T>, valid() == true
  1641. - Returned future<T>, is_ready() = true
  1642. ]]
  1643. [[See:] [`make_ready_future()`]]
  1644. ]
  1645. [endsect]
  1646. [////////////////////////////////////////////////////////////////////////////////]
  1647. [section:make_shared_future Non-member function `make_shared_future()` DEPRECATED]
  1648. template <typename T>
  1649. shared_future<typename decay<T>::type> make_shared_future(T&& value); // DEPRECATED
  1650. shared_future<void> make_shared_future(); // DEPRECATED
  1651. [variablelist
  1652. [[Effects:] [
  1653. The value that is passed in to the function is moved to the shared state of the returned function if it is an rvalue.
  1654. Otherwise the value is copied to the shared state of the returned function.
  1655. .]]
  1656. [[Returns:] [
  1657. - shared_future<T>, if function is given a value of type T
  1658. - shared_future<void>, if the function is not given any inputs.
  1659. ]]
  1660. [[Postcondition:] [
  1661. - Returned shared_future<T>, valid() == true
  1662. - Returned shared_future<T>, is_ready() = true
  1663. ]]
  1664. [[See:] [`make_ready_future()` and `future<>::share()`]]
  1665. ]
  1666. [endsect]
  1667. [endsect]