1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228
|
[/
(C) Copyright 2008-11 Anthony Williams.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
]
[///////////////////////////////////]
[section:reference Futures Reference]
//#include <boost/thread/futures.hpp>
namespace boost
{
namespace future_state // EXTENSION
{
enum state {uninitialized, waiting, ready, moved};
}
enum class future_errc
{
broken_promise,
future_already_retrieved,
promise_already_satisfied,
no_state
};
enum class launch
{
async = unspecified,
deferred = unspecified,
any = async | deferred
};
enum class future_status {
ready, timeout, deferred
};
namespace system
{
template <>
struct is_error_code_enum<future_errc> : public true_type {};
error_code make_error_code(future_errc e);
error_condition make_error_condition(future_errc e);
}
const system::error_category& future_category();
class future_error;
template <typename R>
class promise;
template <typename R>
void swap(promise<R>& x, promise<R>& y) noexcept;
namespace container {
template <class R, class Alloc>
struct uses_allocator<promise<R>, Alloc>:: true_type;
}
template <typename R>
class future;
template <typename R>
class shared_future;
template <typename S>
class packaged_task;
template <class S> void swap(packaged_task<S>&, packaged_task<S>&) noexcept;
template <class S, class Alloc>
struct uses_allocator<packaged_task <S>, Alloc>;
template <class F>
future<typename result_of<typename decay<F>::type()>::type>
async(F f);
template <class F>
future<typename result_of<typename decay<F>::type()>::type>
async(launch policy, F f);
template <class F, class... Args>
future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
async(F&& f, Args&&... args);
template <class F, class... Args>
future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
async(launch policy, F&& f, Args&&... args);
template<typename Iterator>
void wait_for_all(Iterator begin,Iterator end); // EXTENSION
template<typename F1,typename... FS>
void wait_for_all(F1& f1,Fs&... fs); // EXTENSION
template<typename Iterator>
Iterator wait_for_any(Iterator begin,Iterator end); // EXTENSION
template<typename F1,typename... Fs>
unsigned wait_for_any(F1& f1,Fs&... fs); // EXTENSION
template <typename T>
future<typename decay<T>::type> make_future(T&& value); // DEPRECATED
future<void> make_future(); // DEPRECATED
template <typename T>
future<typename decay<T>::type> make_ready_future(T&& value); // EXTENSION
future<void> make_ready_future(); // EXTENSION
template <typename T>
future<T> make_ready_future(exception_ptr ex); // EXTENSION
template <typename T, typename E>
future<T> make_ready_future(E ex); // EXTENSION
template <typename T>
shared_future<typename decay<T>::type> make_shared_future(T&& value); // DEPRECATED
shared_future<void> make_shared_future(); // DEPRECATED
[////////////////////////////////////////]
[section:future_state Enumeration `state`]
namespace future_state
{
enum state {uninitialized, waiting, ready, moved};
}
[endsect]
[/////////////////////////////////////////////]
[section:future_errc Enumeration `future_errc`]
enum class future_errc
{
broken_promise = implementation defined,
future_already_retrieved = implementation defined,
promise_already_satisfied = implementation defined,
no_state = implementation defined
}
The enum values of future_errc are distinct and not zero.
[endsect]
[///////////////////////////////////]
[section:launch Enumeration `launch`]
enum class launch
{
async = unspecified,
deferred = unspecified,
any = async | deferred
};
The enum type launch is a bitmask type with launch::async and launch::deferred denoting individual bits.
[endsect]
[///////////////////////////////////////////////////////////////////////////]
[section:is_error_code_enum Specialization `is_error_code_enum<future_errc>`]
namespace system
{
template <>
struct is_error_code_enum<future_errc> : public true_type {};
}
[endsect]
[///////////////////////////////////////////////////////////////]
[section:make_error_code Non-member function `make_error_code()`]
namespace system
{
error_code make_error_code(future_errc e);
}
[variablelist
[[Returns:] [`error_code(static_cast<int>(e), future_category())`.]]
]
[endsect]
[/////////////////////////////////////////////////////////////////////////]
[section:make_error_condition Non-member function `make_error_condition()`]
namespace system
{
error_condition make_error_condition(future_errc e);
}
[variablelist
[[Returns:] [`error_condition(static_cast<int>(e), future_category())`.]]
]
[endsect]
[///////////////////////////////////////////////////////////////]
[section:future_category Non-member function `future_category()`]
const system::error_category& future_category();
[variablelist
[[Returns:] [A reference to an object of a type derived from class error_category.]]
[[Notes:] [The object's `default_error_condition` and equivalent virtual functions behave as specified for the class `system::error_category`.
The object's `name` virtual function returns a pointer to the string "future".]]
]
[endsect]
[/////////////////////////////////////////]
[section:future_error Class `future_error`]
class future_error
: public std::logic_error
{
public:
future_error(system::error_code ec);
const system::error_code& code() const no_except;
};
[///////////////////////////////]
[section:constructor Constructor]
future_error(system::error_code ec);
[variablelist
[[Effects:] [Constructs a future_error.]]
[[Postconditions:] [`code()==ec` ]]
[[Throws:] [Nothing.]]
]
[endsect]
[/////////////////////////////////////]
[section:code Member function `code()`]
const system::error_code& code() const no_except;
[variablelist
[[Returns:] [The value of `ec` that was passed to the object's constructor.]]
]
[endsect]
[endsect]
[/////////////////////////////////////////////////]
[section:future_status Enumeration `future_status`]
enum class future_status {
ready, timeout, deferred
};
[endsect]
[////////////////////////////////////////////////////]
[section:unique_future __unique_future class template]
template <typename R>
class __unique_future__
{
public:
typedef R value_type; // EXTENSION
__unique_future__(__unique_future__ const& rhs) = delete;
__unique_future__& operator=(__unique_future__ const& rhs) = delete;
__unique_future__() noexcept;
~__unique_future__();
// move support
__unique_future__(__unique_future__ && other) noexcept;
__unique_future__(__unique_future__<__unique_future__<R>>&& rhs); // EXTENSION
__unique_future__& operator=(__unique_future__ && other) noexcept;
// factories
shared_future<R> share();
template<typename F>
__unique_future__<typename boost::result_of<F(__unique_future__&)>::type>
then(F&& func); // EXTENSION
template<typename S, typename F>
__unique_future__<typename boost::result_of<F(__unique_future__&)>::type>
then(S& scheduler, F&& func); // EXTENSION NOT_YET_IMPLEMENTED
template<typename F>
__unique_future__<typename boost::result_of<F(__unique_future__&)>::type>
then(launch policy, F&& func); // EXTENSION
see below unwrap(); // EXTENSION
__unique_future__ fallback_to(); // EXTENSION
void swap(__unique_future__& other) noexcept;
// retrieving the value
see below get();
see below get_or(see below); // EXTENSION
exception_ptr get_exception_ptr(); // EXTENSION
// functions to check state
bool valid() const noexcept;
bool is_ready() const; // EXTENSION
bool has_exception() const; // EXTENSION
bool has_value() const; // EXTENSION
// waiting for the result to be ready
void wait() const;
template <class Rep, class Period>
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
template <class Clock, class Duration>
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
#if defined BOOST_THREAD_USES_DATE_TIME
template<typename Duration>
bool timed_wait(Duration const& rel_time) const; // DEPRECATED SINCE V3.0.0
bool timed_wait_until(boost::system_time const& abs_time) const; // DEPRECATED SINCE V3.0.0
#endif
typedef future_state::state state; // EXTENSION
state get_state() const; // EXTENSION
};
[///////////////////////////////////////////////]
[section:default_constructor Default Constructor]
__unique_future__();
[variablelist
[[Effects:] [Constructs an uninitialized __unique_future__.]]
[[Postconditions:] [[unique_future_is_ready_link `this->is_ready`] returns `false`. [unique_future_get_state_link
`this->get_state()`] returns __uninitialized__.]]
[[Throws:] [Nothing.]]
]
[endsect]
[/////////////////////////////]
[section:destructor Destructor]
~__unique_future__();
[variablelist
[[Effects:] [Destroys `*this`.]]
[[Throws:] [Nothing.]]
]
[endsect]
[/////////////////////////////////////////]
[section:move_constructor Move Constructor]
__unique_future__(__unique_future__ && other);
[variablelist
[[Effects:] [Constructs a new __unique_future__, and transfers ownership of the shared state associated with `other` to `*this`.]]
[[Postconditions:] [[unique_future_get_state_link `this->get_state()`] returns the value of `other->get_state()` prior to the
call. `other->get_state()` returns __uninitialized__. If `other` was associated with a shared state, that result is now
associated with `*this`. `other` is not associated with any shared state.]]
[[Throws:] [Nothing.]]
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
]
[endsect]
[///////////////////////////////////////////////////////////////////]
[section:unwrap_move_constructor Unwrap Move Constructor - EXTENSION]
__unique_future__(__unique_future__<__unique_future__<R>>&& other); // EXTENSION
[warning This constructor is experimental and subject to change in future versions.
There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
[variablelist
[[Requires:] [`other.valid()`.]
[[Effects:] [Constructs a new __unique_future__, and transfers ownership of the shared state associated with `other` and unwrapping the inner future (see `unwrap()`).]]
[[Postconditions:] [[unique_future_get_state_link `this->get_state()`] returns the value of `other->get_state()` prior to the
call. `other->get_state()` returns __uninitialized__. The associated shared state is now
unwrapped and the inner future shared state is associated with `*this`. `other` is not associated with any shared state, `! other.valid()`.]]
[[Throws:] [Nothing.]]
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
]
[endsect]
[////////////////////////////////////////////////]
[section:move_assignment Move Assignment Operator]
__unique_future__& operator=(__unique_future__ && other);
[variablelist
[[Effects:] [Transfers ownership of the shared state associated with `other` to `*this`.]]
[[Postconditions:] [[unique_future_get_state_link `this->get_state()`] returns the value of `other->get_state()` prior to the
call. `other->get_state()` returns __uninitialized__. If `other` was associated with a shared state, that result is now
associated with `*this`. `other` is not associated with any shared state. If `*this` was associated with an asynchronous
result prior to the call, that result no longer has an associated __unique_future__ instance.]]
[[Throws:] [Nothing.]]
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
]
[endsect]
[/////////////////////////////////////]
[section:swap Member function `swap()`]
void swap(__unique_future__ & other) no_except;
[variablelist
[[Effects:] [Swaps ownership of the shared states associated with `other` and `*this`.]]
[[Postconditions:] [[unique_future_get_state_link `this->get_state()`] returns the value of `other->get_state()` prior to the
call. `other->get_state()` returns the value of `this->get_state()` prior to the call. If `other` was associated with a
shared state, that result is now associated with `*this`, otherwise `*this` has no associated result. If `*this` was
associated with a shared state, that result is now associated with `other`, otherwise `other` has no associated result.]]
[[Throws:] [Nothing.]]
]
[endsect]
[///////////////////////////////////]
[section:get Member function `get()`]
R get();
R& __unique_future__<R&>::get();
void __unique_future__<void>::get();
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready as-if by a call to
__unique_future_wait__, and retrieves the result (whether that is a value or an exception).]]
[[Returns:] [
- `__unique_future__<R&>::get()` return the stored reference.
- `__unique_future__<void>::get()`, there is no return value.
- `__unique_future__<R>::get()` returns an rvalue-reference to the value stored in the shared state.
]]
[[Postconditions:] [[unique_future_is_ready_link `this->is_ready()`] returns `true`. [unique_future_get_state_link
`this->get_state()`] returns __ready__.]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
- Any exception stored in the shared state in place of a value.
]]
[[Notes:] [`get()` is an ['interruption point].]]
]
[endsect]
[/////////////////////////////////////////////////////]
[section:get_or Member function `get_or()` - EXTENSION]
R get_or(R&& v); // EXTENSION
R get_or(R const& v); // EXTENSION
R& __unique_future__<R&>::get_or(R& v); // EXTENSION
void __unique_future__<void>::get_or(); // EXTENSION
[warning These functions are experimental and subject to change in future versions.
There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready as-if by a call to
__unique_future_wait__, and depending on whether the shared state `has_value()` the retrieves the result.]]
[[Returns:] [
- `__unique_future__<R&>::get_or(v)` return the stored reference if has_value() and the passes parameter otherwise.
- `__unique_future__<void>::get_or()`, there is no return value, but the function doesn't throws even if the shared state contained an exception.
- `__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`.
]]
[[Postconditions:] [[unique_future_is_ready_link `this->is_ready()`] returns `true`. [unique_future_get_state_link
`this->get_state()`] returns __ready__.]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
]]
[[Notes:] [`get_or()` is an ['interruption point].]]
]
[endsect]
[/////////////////////////////////////]
[section:wait Member function `wait()`]
void wait() const;
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready. If the result is not ready on
entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result
associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
- Any exception thrown by the ['wait callback] if such a callback is called.]]
[[Postconditions:] [[unique_future_is_ready_link `this->is_ready()`] returns `true`. [unique_future_get_state_link
`this->get_state()`] returns __ready__.]]
[[Notes:] [`wait()` is an ['interruption point].]]
]
[endsect]
[//////////////////////////////////////////////////////////////////////////////////]
[section:timed_wait_duration Member function `timed_wait()` DEPRECATED SINCE V3.0.0]
template<typename Duration>
bool timed_wait(Duration const& wait_duration);
[warning
DEPRECATED since 3.00.
Available only up to Boost 1.56.
Use instead __wait_for.
]
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time specified by
`wait_duration` has elapsed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is
invoked prior to waiting.]]
[[Returns:] [`true` if `*this` is associated with a shared state, and that result is ready before the specified time has
elapsed, `false` otherwise.]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
- Any exception thrown by the ['wait callback] if such a callback is called.]]
[[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and
[unique_future_get_state_link `this->get_state()`] returns __ready__.]]
[[Notes:] [`timed_wait()` is an ['interruption point]. `Duration` must be a type that meets the Boost.DateTime time duration requirements.]]
]
[endsect]
[//////////////////////////////////////////////////////////////////////////////////]
[section:timed_wait_absolute Member function `timed_wait()` DEPRECATED SINCE V3.0.0]
bool timed_wait(boost::system_time const& wait_timeout);
[warning
DEPRECATED since 3.00.
Available only up to Boost 1.56.
Use instead __wait_until.
]
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time point specified by
`wait_timeout` has passed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked
prior to waiting.]]
[[Returns:] [`true` if `*this` is associated with a shared state, and that result is ready before the specified time has
passed, `false` otherwise.]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
- Any exception thrown by the ['wait callback] if such a callback is called.]]
[[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and
[unique_future_get_state_link `this->get_state()`] returns __ready__.]]
[[Notes:] [`timed_wait()` is an ['interruption point].]]
]
[endsect]
[/////////////////////////////////////////////]
[section:wait_for Member function `wait_for()`]
template <class Rep, class Period>
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time specified by
`wait_duration` has elapsed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is
invoked prior to waiting.]]
[[Returns:] [
- `future_status::deferred` if the shared state contains a deferred function. (Not implemented yet)
- `future_status::ready` if the shared state is ready.
- `future_status::timeout` if the function is returning because the relative timeout specified by `rel_time` has expired.
]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
- Any exception thrown by the ['wait callback] if such a callback is called.]]
[[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and
[unique_future_get_state_link `this->get_state()`] returns __ready__.]]
[[Notes:] [`wait_for()` is an ['interruption point]. `Duration` must be a type that meets the Boost.DateTime time duration requirements.]]
]
[endsect]
[/////////////////////////////////////////////////]
[section:wait_until Member function `wait_until()`]
template <class Clock, class Duration>
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time point specified by
`wait_timeout` has passed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked
prior to waiting.]]
[[Returns:] [
- `future_status::deferred` if the shared state contains a deferred function. (Not implemented yet)
- `future_status::ready` if the shared state is ready.
- `future_status::timeout` if the function is returning because the absolute timeout specified by `absl_time` has reached.
]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
- Any exception thrown by the ['wait callback] if such a callback is called.]]
[[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and
[unique_future_get_state_link `this->get_state()`] returns __ready__.]]
[[Notes:] [`wait_until()` is an ['interruption point].]]
]
[endsect]
[///////////////////////////////////////]
[section:valid Member function `valid()`]
bool valid() const noexcept;
[variablelist
[[Returns:] [`true` if `*this` is associated with a shared state, `false`
otherwise.]]
[[Throws:] [Nothing.]]
]
[endsect]
[///////////////////////////////////////////////////////]
[section:is_ready Member function `is_ready()` EXTENSION]
bool is_ready() const;
[variablelist
[[Returns:] [`true` if `*this` is associated with a shared state and that result is ready for retrieval, `false`
otherwise.]]
[[Throws:] [Nothing.]]
]
[endsect]
[/////////////////////////////////////////////////////////]
[section:has_value Member function `has_value()` EXTENSION]
bool has_value() const;
[variablelist
[[Returns:] [`true` if `*this` is associated with a shared state, that result is ready for retrieval, and the result is a
stored value, `false` otherwise.]]
[[Throws:] [Nothing.]]
]
[endsect]
[/////////////////////////////////////////////////////////////////]
[section:has_exception Member function `has_exception()` EXTENSION]
bool has_exception() const;
[variablelist
[[Returns:] [`true` if `*this` is associated with a shared state, that result is ready for retrieval, and the result is a
stored exception, `false` otherwise.]]
[[Throws:] [Nothing.]]
]
[endsect]
[/////////////////////////////////////////////////////////////////]
[section:get_exception_ptr Member function `get_exception_ptr()` EXTENSION]
exception_ptr get_exception_ptr();
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready. If the result is not ready on
entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
[[Returns:] [a exception_ptr, storring or not an exception.]]
[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
]
[endsect]
[/////////////////////////////////////////////////////////]
[section:get_state Member function `get_state()` EXTENSION]
future_state::state get_state();
[variablelist
[[Effects:] [Determine the state of the shared state associated with `*this`, if any.]]
[[Returns:] [__uninitialized__ if `*this` is not associated with a shared state. __ready__ if the shared state
associated with `*this` is ready for retrieval, __waiting__ otherwise.]]
[[Throws:] [Nothing.]]
]
[endsect]
[///////////////////////////////////////]
[section:share Member function `share()`]
shared_future<R> share();
[variablelist
[[Returns:] [`shared_future<R>(boost::move(*this))`.]]
[[Postconditions:] [`this->valid() == false`.]]
]
[endsect]
[/////////////////////////////////////////////////]
[section:then Member function `then()` - EXTENSION]
template<typename F>
__unique_future__<typename boost::result_of<F(__unique_future__&)>::type>
then(F&& func); // EXTENSION
template<typename S, typename F>
__unique_future__<typename boost::result_of<F(__unique_future__&)>::type>
then(S& scheduler, F&& func); // EXTENSION NOT_YET_IMPLEMENTED
template<typename F>
__unique_future__<typename boost::result_of<F(__unique_future__&)>::type>
then(launch policy, F&& func); // EXTENSION
[warning These functions are experimental and subject to change in future versions.
There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
[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.]
[variablelist
[[Notes:] [The three functions differ only by input parameters. The first only takes a callable object which accepts a
future object as a parameter. The second function takes a scheduler as the first parameter and a callable object as
the second parameter. The third function takes a launch policy as the first parameter and a callable object as the
second parameter.]]
[[Effects:] [
- The continuation is called when the object's shared state is ready (has a value or exception stored).
- The continuation launches according to the specified policy or scheduler.
- When the scheduler or launch policy is not provided the continuation inherits the
parent's launch policy or scheduler.
- If the parent was created with `promise<<` or with a `packaged_task<>` (has no associated launch policy), the
continuation behaves the same as the third overload with a policy argument of `launch::async | launch::deferred` and
the same argument for func.
- If the parent has a policy of `launch::deferred` and the continuation does not have a specified launch policy or
scheduler, then the parent is filled by immediately calling `.wait()`, and the policy of the antecedent is
`launch::deferred`.
]]
[[Returns:] [An object of type `__unique_future__<typename boost::result_of<F(__unique_future__)>` that refers to the shared state created by the continuation.]]
[[Postconditions:] [
- The `__unique_future__` object passed to the parameter of the continuation function is a copy of the original `__unique_future__`.
- `valid() == false` on original future object immediately after it returns.
]]
]
[endsect]
[///////////////////////////////////////////////////]
[section:unwrap Member function `unwrap()` EXTENSION]
template <typename R2>
__unique_future__<R2> __unique_future__<__unique_future__<R2>>::unwrap(); // EXTENSION
template <typename R2>
__shared_future__<R2> __unique_future__<__shared_future__<R2>>::unwrap(); // EXTENSION
[warning These functions are experimental and subject to change in future versions.
There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
[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.]
[variablelist
[[Notes:] [Removes the outermost future and returns a future with the associated state been a proxy of inner future.]]
[[Effects:] [
- Returns a future that becomes ready when the shared state of the inner future is ready.
]]
[[Returns:] [An object of type future with the associated state been a proxy of inner future.]]
[[Postconditions:] [
- The returned future has `valid() == true` regardless of the validity of the inner future.
]]
]
[endsect]
[endsect]
[////////////////////////////////////////////////////]
[section:shared_future `shared_future` class template]
template <typename R>
class shared_future
{
public:
typedef future_state::state state; // EXTENSION
typedef R value_type; // EXTENSION
shared_future() noexcept;
~shared_future();
// copy support
shared_future(shared_future const& other);
shared_future& operator=(shared_future const& other);
// move support
shared_future(shared_future && other) noexcept;
shared_future(__unique_future__<R> && other) noexcept;
shared_future& operator=(shared_future && other) noexcept;
shared_future& operator=(__unique_future__<R> && other) noexcept;
// factories
template<typename F>
__unique_future__<typename boost::result_of<F(shared_future&)>::type>
then(F&& func); // EXTENSION
template<typename S, typename F>
__unique_future__<typename boost::result_of<F(shared_future&)>::type>
then(S& scheduler, F&& func); // EXTENSION NOT_YET_IMPLEMENTED
template<typename F>
__unique_future__<typename boost::result_of<F(shared_future&)>::type>
then(launch policy, F&& func); // EXTENSION
void swap(shared_future& other);
// retrieving the value
see below get();
exception_ptr get_exception_ptr(); // EXTENSION
// functions to check state, and wait for ready
bool valid() const noexcept;
bool is_ready() const noexcept; // EXTENSION
bool has_exception() const noexcept; // EXTENSION
bool has_value() const noexcept; // EXTENSION
// waiting for the result to be ready
void wait() const;
template <class Rep, class Period>
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
template <class Clock, class Duration>
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
#if defined BOOST_THREAD_USES_DATE_TIME || defined BOOST_THREAD_DONT_USE_CHRONO
template<typename Duration>
bool timed_wait(Duration const& rel_time) const; // DEPRECATED SINCE V3.0.0
bool timed_wait_until(boost::system_time const& abs_time) const; // DEPRECATED SINCE V3.0.0
#endif
state get_state() const noexcept; // EXTENSION
};
[///////////////////////////////////////////////]
[section:default_constructor Default Constructor]
shared_future();
[variablelist
[[Effects:] [Constructs an uninitialized shared_future.]]
[[Postconditions:] [[shared_future_is_ready_link `this->is_ready`] returns `false`. [shared_future_get_state_link
`this->get_state()`] returns __uninitialized__.]]
[[Throws:] [Nothing.]]
]
[endsect]
[///////////////////////////////////]
[section:get Member function `get()`]
const R& get();
R& get();
void get();
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready as-if by a call to
__shared_future_wait__, and returns a `const` reference to the result.]]
[[Returns:] [
- `shared_future<R&>::get()` return the stored reference.
- `shared_future<void>::get()`, there is no return value.
- `shared_future<R>::get()` returns a `const` reference to the value stored in the shared state.
]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
]]
[[Notes:] [`get()` is an ['interruption point].]]
]
[endsect]
[/////////////////////////////////////]
[section:wait Member function `wait()`]
void wait() const;
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready. If the result is not ready on
entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
- Any exception thrown by the
['wait callback] if such a callback is called.]]
[[Postconditions:] [[shared_future_is_ready_link `this->is_ready()`] returns `true`. [shared_future_get_state_link
`this->get_state()`] returns __ready__.]]
[[Notes:] [`wait()` is an ['interruption point].]]
]
[endsect]
[//////////////////////////////////////////////////////////]
[section:timed_wait_duration Member function `timed_wait()`]
template<typename Duration>
bool timed_wait(Duration const& wait_duration);
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time specified by
`wait_duration` has elapsed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is
invoked prior to waiting.]]
[[Returns:] [`true` if `*this` is associated with a shared state, and that result is ready before the specified time has
elapsed, `false` otherwise.]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
- Any exception thrown by the ['wait callback] if such a callback is called.]]
[[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and
[shared_future_get_state_link `this->get_state()`] returns __ready__.]]
[[Notes:] [`timed_wait()` is an ['interruption point]. `Duration` must be a type that meets the Boost.DateTime time duration requirements.]]
]
[endsect]
[//////////////////////////////////////////////////////////]
[section:timed_wait_absolute Member function `timed_wait()`]
bool timed_wait(boost::system_time const& wait_timeout);
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time point specified by
`wait_timeout` has passed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked
prior to waiting.]]
[[Returns:] [`true` if `*this` is associated with a shared state, and that result is ready before the specified time has
passed, `false` otherwise.]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
- Any exception thrown by the ['wait callback] if such a callback is called.]]
[[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and
[shared_future_get_state_link `this->get_state()`] returns __ready__.]]
[[Notes:] [`timed_wait()` is an ['interruption point].]]
]
[endsect]
[/////////////////////////////////////////////]
[section:wait_for Member function `wait_for()`]
template <class Rep, class Period>
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time specified by
`wait_duration` has elapsed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is
invoked prior to waiting.]]
[[Returns:] [
- `future_status::deferred` if the shared state contains a deferred function. (Not implemented yet)
- `future_status::ready` if the shared state is ready.
- `future_status::timeout` if the function is returning because the relative timeout specified by `rel_time` has expired.
]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
- Any exception thrown by the ['wait callback] if such a callback is called.]]
[[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and
[shared_future_get_state_link `this->get_state()`] returns __ready__.]]
[[Notes:] [`timed_wait()` is an ['interruption point]. `Duration` must be a type that meets the Boost.DateTime time duration requirements.]]
]
[endsect]
[/////////////////////////////////////////////////]
[section:wait_until Member function `wait_until()`]
template <class Clock, class Duration>
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready, or the time point specified by
`wait_timeout` has passed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked
prior to waiting.]]
[[Returns:] [
- `future_status::deferred` if the shared state contains a deferred function. (Not implemented yet)
- `future_status::ready` if the shared state is ready.
- `future_status::timeout` if the function is returning because the absolute timeout specified by `absl_time` has reached.
]]
[[Throws:] [
- __future_uninitialized__ if `*this` is not associated with a shared state.
- __thread_interrupted__ if the result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.
- Any exception thrown by the ['wait callback] if such a callback is called.
]]
[[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and
[shared_future_get_state_link `this->get_state()`] returns __ready__.]]
[[Notes:] [`timed_wait()` is an ['interruption point].]]
]
[endsect]
[///////////////////////////////////////]
[section:valid Member function `valid()`]
bool valid() const noexcept;
[variablelist
[[Returns:] [`true` if `*this` is associated with a shared state, `false`
otherwise.]]
[[Throws:] [Nothing.]]
]
[endsect]
[///////////////////////////////////////////////////////]
[section:is_ready Member function `is_ready()` EXTENSION]
bool is_ready() const;
[variablelist
[[Returns:] [`true` if `*this` is associated with a shared state, and that result is ready for retrieval, `false`
otherwise.]]
[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
]
[endsect]
[/////////////////////////////////////////////////////////]
[section:has_value Member function `has_value()` EXTENSION]
bool has_value() const;
[variablelist
[[Returns:] [`true` if `*this` is associated with a shared state, that result is ready for retrieval, and the result is a
stored value, `false` otherwise.]]
[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
]
[endsect]
[/////////////////////////////////////////////////////////////////]
[section:has_exception Member function `has_exception()` EXTENSION]
bool has_exception() const;
[variablelist
[[Returns:] [`true` if `*this` is associated with a shared state, that result is ready for retrieval, and the result is a
stored exception, `false` otherwise.]]
[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
]
[endsect]
[/////////////////////////////////////////////////////////////////]
[section:get_exception_ptr Member function `get_exception_ptr()` EXTENSION]
exception_ptr get_exception_ptr();
[variablelist
[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready. If the result is not ready on
entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
[[Returns:] [a exception_ptr, storring or not an exception.]]
[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
]
[endsect]
[/////////////////////////////////////////////////////////]
[section:get_state Member function `get_state()` EXTENSION]
future_state::state get_state();
[variablelist
[[Effects:] [Determine the state of the shared state associated with `*this`, if any.]]
[[Returns:] [__uninitialized__ if `*this` is not associated with a shared state. __ready__ if the shared state
associated with `*this` is ready for retrieval, __waiting__ otherwise.]]
[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
]
[endsect]
[///////////////////////////////////////////////]
[section:then Member function `then()` EXTENSION]
template<typename F>
__unique_future__<typename boost::result_of<F(shared_future&)>::type>
then(F&& func); // EXTENSION
template<typename S, typename F>
__unique_future__<typename boost::result_of<F(shared_future&)>::type>
then(S& scheduler, F&& func); // EXTENSION NOT_YET_IMPLEMENTED
template<typename F>
__unique_future__<typename boost::result_of<F(shared_future&)>::type>
then(launch policy, F&& func); // EXTENSION
[warning These functions are experimental and subject to change in future versions.
There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
[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.]
[variablelist
[[Notes:] [The three functions differ only by input parameters. The first only takes a callable object which accepts a
shared_future object as a parameter. The second function takes a scheduler as the first parameter and a callable object as
the second parameter. The third function takes a launch policy as the first parameter and a callable object as the
second parameter.]]
[[Effects:] [
- The continuation is called when the object's shared state is ready (has a value or exception stored).
- The continuation launches according to the specified policy or scheduler.
- When the scheduler or launch policy is not provided the continuation inherits the
parent's launch policy or scheduler.
- If the parent was created with `promise` or with a `packaged_task` (has no associated launch policy), the
continuation behaves the same as the third overload with a policy argument of `launch::async | launch::deferred` and
the same argument for func.
- If the parent has a policy of `launch::deferred` and the continuation does not have a specified launch policy or
scheduler, then the parent is filled by immediately calling `.wait()`, and the policy of the antecedent is
`launch::deferred`
]]
[[Returns:] [An object of type `__unique_future__<typename boost::result_of<F(shared_future)>` that refers to the shared state created by the continuation.]]
[[Postconditions:] [
- The future object is moved to the parameter of the continuation function .
- `valid() == false` on original future object immediately after it returns.
]]
]
[endsect]
[endsect]
[////////////////////////////////////////]
[section:promise `promise` class template]
template <typename R>
class promise
{
public:
typedef R value_type; // EXTENSION
promise();
template <class Allocator>
promise(allocator_arg_t, Allocator a);
promise & operator=(promise const& rhs) = delete;
promise(promise const& rhs) = delete;
~promise();
// Move support
promise(promise && rhs) noexcept;;
promise & operator=(promise&& rhs) noexcept;;
void swap(promise& other) noexcept;
// Result retrieval
__unique_future__<R> get_future();
// Set the value
void set_value(see below);
void set_exception(boost::exception_ptr e);
template <typename E>
void set_exception(E e); // EXTENSION
// setting the result with deferred notification
void set_value_at_thread_exit(see below);
void set_exception_at_thread_exit(exception_ptr p);
template <typename E>
void set_exception_at_thread_exit(E p); // EXTENSION
template<typename F>
void set_wait_callback(F f); // EXTENSION
};
[///////////////////////////////////////////////]
[section:default_constructor Default Constructor]
promise();
[variablelist
[[Effects:] [Constructs a new __promise__ with no associated result.]]
[[Throws:] [Nothing.]]
]
[endsect]
[///////////////////////////////////////////////]
[section:alloc_constructor Allocator Constructor]
template <class Allocator>
promise(allocator_arg_t, Allocator a);
[variablelist
[[Effects:] [Constructs a new __promise__ with no associated result using the allocator `a`.]]
[[Throws:] [Nothing.]]
[[Notes:] [Available only if BOOST_THREAD_FUTURE_USES_ALLOCATORS is defined.]]
]
[endsect]
[/////////////////////////////////////////]
[section:move_constructor Move Constructor]
promise(promise && other);
[variablelist
[[Effects:] [Constructs a new __promise__, and transfers ownership of the result associated with `other` to `*this`, leaving `other`
with no associated result.]]
[[Throws:] [Nothing.]]
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
]
[endsect]
[////////////////////////////////////////////////]
[section:move_assignment Move Assignment Operator]
promise& operator=(promise && other);
[variablelist
[[Effects:] [Transfers ownership of the result associated with `other` to `*this`, leaving `other` with no associated result. If there
was already a result associated with `*this`, and that result was not ['ready], sets any futures associated with that result to
['ready] with a __broken_promise__ exception as the result. ]]
[[Throws:] [Nothing.]]
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
]
[endsect]
[/////////////////////////////]
[section:destructor Destructor]
~promise();
[variablelist
[[Effects:] [Destroys `*this`. If there was a result associated with `*this`, and that result is not ['ready], sets any futures
associated with that task to ['ready] with a __broken_promise__ exception as the result.]]
[[Throws:] [Nothing.]]
]
[endsect]
[/////////////////////////////////////////////////]
[section:get_future Member Function `get_future()`]
__unique_future__<R> get_future();
[variablelist
[[Effects:] [If `*this` was not associated with a result, allocate storage for a new shared state and associate it with
`*this`. Returns a __unique_future__ associated with the result associated with `*this`. ]]
[[Throws:] [__future_already_retrieved__ if the future associated with the task has already been retrieved. `std::bad_alloc` if any
memory necessary could not be allocated.]]
]
[endsect]
[///////////////////////////////////////////////]
[section:set_value Member Function `set_value()`]
void set_value(R&& r);
void set_value(const R& r);
void promise<R&>::set_value(R& r);
void promise<void>::set_value();
[variablelist
[[Effects:] [
- 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`.
- Store the value `r` in the shared state associated with `*this`. Any threads blocked waiting for the asynchronous
result are woken.
]]
[[Postconditions:] [All futures waiting on the shared state are ['ready] and __unique_future_has_value__ or
__shared_future_has_value__ for those futures shall return `true`.]]
[[Throws:] [
- __promise_already_satisfied__ if the result associated with `*this` is already ['ready].
- __broken_promise__ if `*this` has no shared state.
- `std::bad_alloc` if the memory required for storage of the result cannot be allocated.
- Any exception thrown by the copy or move-constructor of `R`.]]
]
[endsect]
[///////////////////////////////////////////////////////]
[section:set_exception Member Function `set_exception()`]
void set_exception(boost::exception_ptr e);
template <typename E>
void set_exception(E e); // EXTENSION
[variablelist
[[Effects:] [
- 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`.
- Store the exception `e` in the shared state associated with `*this`. Any threads blocked waiting for the asynchronous
result are woken.]]
[[Postconditions:] [All futures waiting on the shared state are ['ready] and __unique_future_has_exception__ or
__shared_future_has_exception__ for those futures shall return `true`.]]
[[Throws:] [
- __promise_already_satisfied__ if the result associated with `*this` is already ['ready].
- __broken_promise__ if `*this` has no shared state.
- `std::bad_alloc` if the memory required for storage of the result cannot be allocated.
]]
]
[endsect]
[/////////////////////////////////////////////////////////////////////////////]
[section:set_value_at_thread_exit Member Function `set_value_at_thread_exit()`]
void set_value_at_thread_exit(R&& r);
void set_value_at_thread_exit(const R& r);
void promise<R&>::set_value_at_thread_exit(R& r);
void promise<void>::set_value_at_thread_exit();
[variablelist
[[Effects:] [
Stores the value r in the shared state without making that state ready immediately.
Schedules that state to be made ready when the current thread exits, after all objects of thread storage duration
associated with the current thread have been destroyed.]]
[[Throws:] [
- __promise_already_satisfied__ if the result associated with `*this` is already ['ready].
- __broken_promise__ if `*this` has no shared state.
- `std::bad_alloc` if the memory required for storage of the result cannot be allocated.
- Any exception thrown by the copy or move-constructor of `R`.
]]
]
[endsect]
[/////////////////////////////////////////////////////////////////////////////////////]
[section:set_exception_at_thread_exit Member Function `set_exception_at_thread_exit()`]
void set_exception_at_thread_exit(boost::exception_ptr e);
template <typename E>
void set_exception_at_thread_exit(E p); // EXTENSION
[variablelist
[[Effects:] [
Stores the exception pointer p in the shared state without making that state ready immediately.
Schedules that state to be made ready when the current thread exits, after all objects of thread storage duration
associated with the current thread have been destroyed.]]
[[Postconditions:] [All futures waiting on the shared state are ['ready] and __unique_future_has_exception__ or
__shared_future_has_exception__ for those futures shall return `true`.]]
[[Throws:] [
- __promise_already_satisfied__ if the result associated with `*this` is already ['ready].
- __broken_promise__ if `*this` has no shared state.
- `std::bad_alloc` if the memory required for storage of the result cannot be allocated.
]]
]
[endsect]
[/////////////////////////////////////////////////////////////////////////]
[section:set_wait_callback Member Function `set_wait_callback()` EXTENSION]
template<typename F>
void set_wait_callback(F f);
[variablelist
[[Preconditions:] [The expression `f(t)` where `t` is a lvalue of type __promise__ shall be well-formed. Invoking a copy of
`f` shall have the same effect as invoking `f`]]
[[Effects:] [Store a copy of `f` with the shared state associated with `*this` as a ['wait callback]. This will replace any
existing wait callback store alongside that result. If a thread subsequently calls one of the wait functions on a __unique_future__
or __shared_future__ associated with this result, and the result is not ['ready], `f(*this)` shall be invoked.]]
[[Throws:] [`std::bad_alloc` if memory cannot be allocated for the required storage.]]
]
[endsect]
[endsect]
[////////////////////////////////////////////////////]
[section:packaged_task `packaged_task` class template]
template<typename S>
class packaged_task;
template<typename R
, class... ArgTypes
>
class packaged_task<R(ArgTypes)>
{
public:
packaged_task(packaged_task const&) = delete;
packaged_task& operator=(packaged_task const&) = delete;
// construction and destruction
packaged_task() noexcept;
explicit packaged_task(R(*f)(ArgTypes...));
template <class F>
explicit packaged_task(F&& f);
template <class Allocator>
packaged_task(allocator_arg_t, Allocator a, R(*f)(ArgTypes...));
template <class F, class Allocator>
packaged_task(allocator_arg_t, Allocator a, F&& f);
~packaged_task()
{}
// move support
packaged_task(packaged_task&& other) noexcept;
packaged_task& operator=(packaged_task&& other) noexcept;
void swap(packaged_task& other) noexcept;
bool valid() const noexcept;
// result retrieval
__unique_future__<R> get_future();
// execution
void operator()(ArgTypes... );
void make_ready_at_thread_exit(ArgTypes...);
void reset();
template<typename F>
void set_wait_callback(F f); // EXTENSION
};
[/////////////////////////////////////////]
[section:task_constructor Task Constructor]
packaged_task(R(*f)(ArgTypes...));
template<typename F>
packaged_task(F&&f);
[variablelist
[[Preconditions:] [`f()` is a valid expression with a return type convertible to `R`. Invoking a copy of `f` must behave the same
as invoking `f`.]]
[[Effects:] [Constructs a new __packaged_task__ with `boost::forward<F>(f)` stored as the associated task.]]
[[Throws:] [
- Any exceptions thrown by the copy (or move) constructor of `f`.
- `std::bad_alloc` if memory for the internal data structures could not be allocated.
]]
[[Notes:] [The R(*f)(ArgTypes...)) overload to allow passing a function without needing to use `&`.]]
[[Remark:] [This constructor doesn't participate in overload resolution if decay<F>::type is the same type as boost::packaged_task<R>.]]
]
[endsect]
[///////////////////////////////////////////////]
[section:alloc_constructor Allocator Constructor]
template <class Allocator>
packaged_task(allocator_arg_t, Allocator a, R(*f)(ArgTypes...));
template <class F, class Allocator>
packaged_task(allocator_arg_t, Allocator a, F&& f);
[variablelist
[[Preconditions:] [`f()` is a valid expression with a return type convertible to `R`. Invoking a copy of `f` shall behave the same
as invoking `f`.]]
[[Effects:] [Constructs a new __packaged_task with `boost::forward<F>(f)` stored as the associated task using the allocator `a`.]]
[[Throws:] [Any exceptions thrown by the copy (or move) constructor of `f`. `std::bad_alloc` if memory for the internal data
structures could not be allocated.]]
[[Notes:] [Available only if BOOST_THREAD_FUTURE_USES_ALLOCATORS is defined.]]
[[Notes:] [The R(*f)(ArgTypes...)) overload to allow passing a function without needing to use `&`.]]
]
[endsect]
[/////////////////////////////////////////]
[section:move_constructor Move Constructor]
packaged_task(packaged_task && other);
[variablelist
[[Effects:] [Constructs a new __packaged_task__, and transfers ownership of the task associated with `other` to `*this`, leaving `other`
with no associated task.]]
[[Throws:] [Nothing.]]
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
]
[endsect]
[////////////////////////////////////////////////]
[section:move_assignment Move Assignment Operator]
packaged_task& operator=(packaged_task && other);
[variablelist
[[Effects:] [Transfers ownership of the task associated with `other` to `*this`, leaving `other` with no associated task. If there
was already a task associated with `*this`, and that task has not been invoked, sets any futures associated with that task to
['ready] with a __broken_promise__ exception as the result. ]]
[[Throws:] [Nothing.]]
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
]
[endsect]
[/////////////////////////////]
[section:destructor Destructor]
~packaged_task();
[variablelist
[[Effects:] [Destroys `*this`. If there was a task associated with `*this`, and that task has not been invoked, sets any futures
associated with that task to ['ready] with a __broken_promise__ exception as the result.]]
[[Throws:] [Nothing.]]
]
[endsect]
[/////////////////////////////////////////////////]
[section:get_future Member Function `get_future()`]
__unique_future__<R> get_future();
[variablelist
[[Effects:] [Returns a __unique_future__ associated with the result of the task associated with `*this`. ]]
[[Throws:] [__task_moved__ if ownership of the task associated with `*this` has been moved to another instance of
__packaged_task__. __future_already_retrieved__ if the future associated with the task has already been retrieved.]]
]
[endsect]
[////////////////////////////////////////////////////]
[section:call_operator Member Function `operator()()`]
void operator()();
[variablelist
[[Effects:] [Invoke the task associated with `*this` and store the result in the corresponding future. If the task returns normally,
the return value is stored as the shared state, otherwise the exception thrown is stored. Any threads blocked waiting for the
shared state associated with this task are woken.]]
[[Postconditions:] [All futures waiting on the shared state are ['ready]]]
[[Throws:] [
- __task_moved__ if ownership of the task associated with `*this` has been moved to another instance of __packaged_task__.
- __task_already_started__ if the task has already been invoked.]]
]
[endsect]
[///////////////////////////////////////////////////////////////////////////////]
[section:make_ready_at_thread_exit Member Function `make_ready_at_thread_exit()`]
void make_ready_at_thread_exit(ArgTypes...);
[variablelist
[[Effects:] [Invoke the task associated with `*this` and store the result in the corresponding future. If the task returns normally,
the return value is stored as the shared state, otherwise the exception thrown is stored.
In either case, this is done without making that state ready immediately.
Schedules the shared state to be made ready when the current thread exits, after all objects of thread storage
duration associated with the current thread have been destroyed.]]
[[Throws:] [
- __task_moved__ if ownership of the task associated with `*this` has been moved to another instance of __packaged_task__.
- __task_already_started__ if the task has already been invoked.
]]
]
[endsect]
[///////////////////////////////////////]
[section:reset Member Function `reset()`]
void reset();
[variablelist
[[Effects:] [Reset the state of the packaged_task so that it can be called again.]]
[[Throws:] [__task_moved__ if ownership of the task associated with `*this` has been moved to another instance of
__packaged_task__.]]
]
[endsect]
[/////////////////////////////////////////////////////////////////////////]
[section:set_wait_callback Member Function `set_wait_callback()` EXTENSION]
template<typename F>
void set_wait_callback(F f);
[variablelist
[[Preconditions:] [The expression `f(t)` where `t` is a lvalue of type __packaged_task__ shall be well-formed. Invoking a copy of
`f` shall have the same effect as invoking `f`]]
[[Effects:] [Store a copy of `f` with the task associated with `*this` as a ['wait callback]. This will replace any existing wait
callback store alongside that task. If a thread subsequently calls one of the wait functions on a __unique_future__ or
__shared_future__ associated with this task, and the result of the task is not ['ready], `f(*this)` shall be invoked.]]
[[Throws:] [__task_moved__ if ownership of the task associated with `*this` has been moved to another instance of
__packaged_task__.]]
]
[endsect]
[endsect]
[//////////////////////////////////////////////////////]
[section:decay_copy Non-member function `decay_copy()`]
template <class T>
typename decay<T>::type decay_copy(T&& v)
{
return boost::forward<T>(v);
}
[endsect]
[///////////////////////////////////////////]
[section:async Non-member function `async()`]
The function template async provides a mechanism to launch a function potentially in a new thread and
provides the result of the function in a future object with which it shares a shared state.
[warning `async(launch::deferred, F)` is NOT YET IMPLEMENTED!]
[heading Non-Variadic variant]
template <class F>
__unique_future__<typename result_of<typename decay<F>::type()>::type>
async(F&& f);
template <class F>
__unique_future__<typename result_of<typename decay<F>::type()>::type>
async(launch policy, F&& f);
[variablelist
[[Requires:] [
``
decay_copy(boost::forward<F>(f))()
``
shall be a valid expression.
]]
[[Effects] [
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`.
The second function creates a shared state that is associated with the returned future object.
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):
- 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.
- 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.)
- if no valid launch policy is provided the behaviour is undefined.
]]
[[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`.]]
[[Synchronization:] [Regardless of the provided policy argument,
- 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
- 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.)
If the implementation chooses the `launch::async` policy,
- 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;
- 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.
]]
[[Throws:][`system_error` if policy is `launch::async` and the implementation is unable to start a new thread.
]]
[[Error conditions:] [
- `resource_unavailable_try_again` - if policy is `launch::async` and the system is unable to start a new thread.
]]
[[Remarks:] [The first signature shall not participate in overload resolution if decay<F>::type is boost::launch.
]]
]
[heading Variadic variant]
template <class F, class... Args>
__unique_future__<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
async(F&& f, Args&&... args);
template <class F, class... Args>
__unique_future__<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
async(launch policy, F&& f, Args&&... args);
[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.]
[variablelist
[[Requires:] [
`F` and each `Ti` in `Args` shall satisfy the `MoveConstructible` requirements.
invoke (decay_copy (boost::forward<F>(f)), decay_copy (boost::forward<Args>(args))...)
shall be a valid expression.
]]
[[Effects:] [
- 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`.
- The second function creates a shared state that is associated with the returned future object.
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):
- if `policy & launch::async` is non-zero - calls `invoke(decay_copy(forward<F>(f)), decay_copy (forward<Args>(args))...)`
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 `invoke(decay_copy(boost::forward<F>(f)), decay_copy (boost::forward<Args>(args))...)`
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.
- if `policy & launch::deferred` is non-zero - Stores `decay_copy(forward<F>(f))` and `decay_copy(forward<Args>(args))...` in the shared state.
These copies of `f` and `args` constitute a deferred function. Invocation of the deferred function evaluates
`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))...`.
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 `invoke(move(g), move(xyz))` begins, the function is no longer considered deferred.
- if no valid launch policy is provided the behaviour is undefined.
]]
[[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.]]
[[Returns:] [An object of type `__unique_future__<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>`
that refers to the shared state created by this call to `async`.]]
[[Synchronization:] [Regardless of the provided policy argument,
- 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
- 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.)
If the implementation chooses the `launch::async` policy,
- a call to a 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;
- 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.
]]
[[Throws:] [`system_error` if policy is `launch::async` and the implementation is unable to start a new thread.
]]
[[Error conditions:][
- `resource_unavailable_try_again` - if policy is `launch::async` and the system is unable to start a new thread.
]]
[[Remarks:] [The first signature shall not participate in overload resolution if decay<F>::type is boost::launch.
]]
]
[endsect]
[/////////////////////////////////////////////////////////////////////]
[section:wait_for_any Non-member function `wait_for_any()` - EXTENSION]
template<typename Iterator>
Iterator wait_for_any(Iterator begin,Iterator end); // EXTENSION
template<typename F1,typename F2>
unsigned wait_for_any(F1& f1,F2& f2); // EXTENSION
template<typename F1,typename F2,typename F3>
unsigned wait_for_any(F1& f1,F2& f2,F3& f3); // EXTENSION
template<typename F1,typename F2,typename F3,typename F4>
unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4); // EXTENSION
template<typename F1,typename F2,typename F3,typename F4,typename F5>
unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5); // EXTENSION
[variablelist
[[Preconditions:] [The types `Fn` shall be specializations of
__unique_future__ or __shared_future__, and `Iterator` shall be a
forward iterator with a `value_type` which is a specialization of
__unique_future__ or __shared_future__.]]
[[Effects:] [Waits until at least one of the specified futures is ['ready].]]
[[Returns:] [The range-based overload returns an `Iterator` identifying the first future in the range that was detected as
['ready]. The remaining overloads return the zero-based index of the first future that was detected as ['ready] (first parameter =>
0, second parameter => 1, etc.).]]
[[Throws:] [__thread_interrupted__ if the current thread is interrupted. Any exception thrown by the ['wait callback] associated
with any of the futures being waited for. `std::bad_alloc` if memory could not be allocated for the internal wait structures.]]
[[Notes:] [`wait_for_any()` is an ['interruption point].]]
]
[endsect]
[/////////////////////////////////////////////////////////////////////]
[section:wait_for_all Non-member function `wait_for_all()` - EXTENSION]
template<typename Iterator>
void wait_for_all(Iterator begin,Iterator end); // EXTENSION
template<typename F1,typename F2>
void wait_for_all(F1& f1,F2& f2); // EXTENSION
template<typename F1,typename F2,typename F3>
void wait_for_all(F1& f1,F2& f2,F3& f3); // EXTENSION
template<typename F1,typename F2,typename F3,typename F4>
void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4); // EXTENSION
template<typename F1,typename F2,typename F3,typename F4,typename F5>
void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5); // EXTENSION
[variablelist
[[Preconditions:] [The types `Fn` shall be specializations of
__unique_future__ or __shared_future__, and `Iterator` shall be a
forward iterator with a `value_type` which is a specialization of
__unique_future__ or __shared_future__.]]
[[Effects:] [Waits until all of the specified futures are ['ready].]]
[[Throws:] [Any exceptions thrown by a call to `wait()` on the specified futures.]]
[[Notes:] [`wait_for_all()` is an ['interruption point].]]
]
[endsect]
[/////////////////////////////////////////////////////////////////////////////]
[section:make_ready_future Non-member function `make_ready_future()` EXTENSION]
template <typename T>
future<typename decay<T>::type> make_ready_future(T&& value); // EXTENSION
future<void> make_ready_future(); // EXTENSION
template <typename T>
future<T> make_ready_future(exception_ptr ex); // EXTENSION
template <typename T, typename E>
future<T> make_ready_future(E ex); // EXTENSION
[variablelist
[[Effects:] [
- value prototype: The value that is passed into the function is moved to the shared state of the returned function if it is an rvalue.
Otherwise the value is copied to the shared state of the returned function.
- exception: The exception that is passed into the function is copied to the shared state of the returned function.
.]]
[[Returns:] [
- a ready future with the value set with `value`
- a ready future with the exception set with `ex`
- a ready future<void> with the value set (void).
]]
[[Postcondition:] [
- Returned future, valid() == true
- Returned future, is_ready() = true
- Returned future, has_value() = true or has_exception() depending on the prototype.
]]
]
[endsect]
[//////////////////////////////////////////////////////////////////]
[section:make_future Non-member function `make_future()` DEPRECATED]
template <typename T>
future<typename decay<T>::type> make_future(T&& value); // DEPRECATED
future<void> make_future(); // DEPRECATED
[variablelist
[[Effects:] [
The value that is passed into the function is moved to the shared state of the returned function if it is an rvalue.
Otherwise the value is copied to the shared state of the returned function.
.]]
[[Returns:] [
- future<T>, if function is given a value of type T
- future<void>, if the function is not given any inputs.
]]
[[Postcondition:] [
- Returned future<T>, valid() == true
- Returned future<T>, is_ready() = true
]]
[[See:] [`make_ready_future()`]]
]
[endsect]
[////////////////////////////////////////////////////////////////////////////////]
[section:make_shared_future Non-member function `make_shared_future()` DEPRECATED]
template <typename T>
shared_future<typename decay<T>::type> make_shared_future(T&& value); // DEPRECATED
shared_future<void> make_shared_future(); // DEPRECATED
[variablelist
[[Effects:] [
The value that is passed in to the function is moved to the shared state of the returned function if it is an rvalue.
Otherwise the value is copied to the shared state of the returned function.
.]]
[[Returns:] [
- shared_future<T>, if function is given a value of type T
- shared_future<void>, if the function is not given any inputs.
]]
[[Postcondition:] [
- Returned shared_future<T>, valid() == true
- Returned shared_future<T>, is_ready() = true
]]
[[See:] [`make_ready_future()` and `future<>::share()`]]
]
[endsect]
[endsect]
|