/usr/include/boost/variant/variant.hpp is in libboost1.62-dev 1.62.0+dfsg-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 | //-----------------------------------------------------------------------------
// boost variant/variant.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2002-2003 Eric Friedman, Itay Maman
// Copyright (c) 2012-2016 Antony Polukhin
//
// 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)
// Thanks to Adam Romanek for providing patches for exception-disabled env.
#ifndef BOOST_VARIANT_VARIANT_HPP
#define BOOST_VARIANT_VARIANT_HPP
#include <cstddef> // for std::size_t
#include <new> // for placement new
#include <boost/type_index.hpp>
#include <boost/variant/detail/config.hpp>
#include <boost/mpl/aux_/value_wknd.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/variant/detail/backup_holder.hpp>
#include <boost/variant/detail/enable_recursive_fwd.hpp>
#include <boost/variant/detail/forced_return.hpp>
#include <boost/variant/detail/initializer.hpp>
#include <boost/variant/detail/make_variant_list.hpp>
#include <boost/variant/detail/over_sequence.hpp>
#include <boost/variant/detail/visitation_impl.hpp>
#include <boost/variant/detail/hash_variant.hpp>
#include <boost/variant/detail/generic_result_type.hpp>
#include <boost/variant/detail/move.hpp>
#include <boost/detail/no_exceptions_support.hpp>
#include <boost/detail/reference_content.hpp>
#include <boost/aligned_storage.hpp>
#include <boost/blank.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/static_assert.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/type_traits/alignment_of.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/type_traits/has_nothrow_constructor.hpp>
#include <boost/type_traits/has_nothrow_copy.hpp>
#include <boost/type_traits/is_nothrow_move_assignable.hpp>
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_rvalue_reference.hpp>
#include <boost/type_traits/is_constructible.hpp>
#include <boost/type_traits/add_lvalue_reference.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/utility/declval.hpp>
#include <boost/variant/recursive_wrapper_fwd.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/is_sequence.hpp>
#include <boost/mpl/iterator_range.hpp>
#include <boost/mpl/iter_fold_if.hpp>
#include <boost/mpl/logical.hpp>
#include <boost/mpl/max_element.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/protect.hpp>
#include <boost/mpl/push_front.hpp>
#include <boost/mpl/same_as.hpp>
#include <boost/mpl/size_t.hpp>
#include <boost/mpl/sizeof.hpp>
#include <boost/mpl/transform.hpp>
///////////////////////////////////////////////////////////////////////////////
// Implementation Macros:
//
// BOOST_VARIANT_VISITATION_UNROLLING_LIMIT
// Defined in boost/variant/detail/visitation_impl.hpp.
//
// BOOST_VARIANT_MINIMIZE_SIZE
// When #defined, implementation employs all known means to minimize the
// size of variant obje cts. However, often unsuccessful due to alignment
// issues, and potentially harmful to runtime speed, so not enabled by
// default. (TODO: Investigate further.)
#if defined(BOOST_VARIANT_MINIMIZE_SIZE)
# include <climits> // for SCHAR_MAX
# include <boost/mpl/eval_if.hpp>
# include <boost/mpl/equal_to.hpp>
# include <boost/mpl/identity.hpp>
# include <boost/mpl/int.hpp>
# include <boost/mpl/if.hpp>
# include <boost/mpl/less.hpp>
# include <boost/mpl/long.hpp>
# include <boost/mpl/O1_size.hpp>
#endif
namespace boost {
namespace detail { namespace variant {
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction max_value
//
// Finds the maximum value of the unary metafunction F over Sequence.
//
template <typename Sequence, typename F>
struct max_value
{
private: // helpers, for metafunction result (below)
typedef typename mpl::transform1<Sequence, F>::type transformed_;
typedef typename mpl::max_element<transformed_
>::type max_it;
public: // metafunction result
typedef typename mpl::deref<max_it>::type
type;
};
struct add_alignment
{
template <typename State, typename Item>
struct apply
: mpl::size_t<
::boost::math::static_lcm<
BOOST_MPL_AUX_VALUE_WKND(State)::value
, ::boost::alignment_of<Item>::value
>::value
>
{};
};
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction find_fallback_type
//
// Provides a fallback (i.e., nothrow default-constructible) type from the
// specified sequence, or no_fallback_type if not found.
//
// This implementation is designed to prefer boost::blank over other potential
// fallback types, regardless of its position in the specified sequence.
//
class no_fallback_type;
struct find_fallback_type_pred
{
template <typename Iterator>
struct apply
{
private:
typedef typename mpl::deref<Iterator>::type t_;
public:
typedef mpl::not_< has_nothrow_constructor<t_> > type;
};
};
template <typename Types>
struct find_fallback_type
{
private: // helpers, for metafunction result (below)
typedef typename mpl::end<Types>::type end_it;
// [Find the first suitable fallback type...]
typedef typename mpl::iter_fold_if<
Types
, mpl::int_<0>, mpl::protect< mpl::next<> >
, mpl::protect< find_fallback_type_pred >
>::type first_result_;
typedef typename first_result_::first first_result_index;
typedef typename first_result_::second first_result_it;
// [...now search the rest of the sequence for boost::blank...]
typedef typename mpl::iter_fold_if<
mpl::iterator_range< first_result_it,end_it >
, first_result_index, mpl::protect< mpl::next<> >
, mpl::protect< mpl::not_same_as<boost::blank> >
>::type second_result_;
typedef typename second_result_::second second_result_it;
public: // metafunction result
// [...and return the results of the search:]
typedef typename mpl::eval_if<
is_same< second_result_it,end_it >
, mpl::if_<
is_same< first_result_it,end_it >
, mpl::pair< no_fallback_type,no_fallback_type >
, first_result_
>
, mpl::identity< second_result_ >
>::type type;
};
#ifndef BOOST_NO_CXX11_NOEXCEPT
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction is_variant_move_noexcept_constructible
//
// Returns true_type if all the types are nothrow move constructible.
//
template <class Types>
struct is_variant_move_noexcept_constructible {
typedef typename boost::mpl::find_if<
Types, mpl::not_<boost::is_nothrow_move_constructible<boost::mpl::_1> >
>::type iterator_t;
typedef typename boost::mpl::end<Types>::type end_t;
typedef typename boost::is_same<
iterator_t, end_t
>::type type;
};
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction is_variant_move_noexcept_assignable
//
// Returns true_type if all the types are nothrow move constructible.
//
template <class Types>
struct is_variant_move_noexcept_assignable {
typedef typename boost::mpl::find_if<
Types, mpl::not_<boost::is_nothrow_move_assignable<boost::mpl::_1> >
>::type iterator_t;
typedef typename boost::mpl::end<Types>::type end_t;
typedef typename boost::is_same<
iterator_t, end_t
>::type type;
};
#endif // BOOST_NO_CXX11_NOEXCEPT
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction is_variant_constructible_from
//
// Derives from true_type if at least one variant's type is constructible from T.
//
template <class T1, class T2>
struct is_constructible_ext:
boost::mpl::or_<
boost::is_constructible<
T1,
T2
>,
boost::is_constructible<
T1,
typename boost::add_lvalue_reference<T2>::type
>
>
{};
template <class T, class Types>
struct is_variant_constructible_from:
boost::mpl::not_< boost::is_same<
typename boost::mpl::find_if<
Types,
is_constructible_ext<boost::mpl::_1, T>
>::type,
typename boost::mpl::end<Types>::type
> >
{};
template <BOOST_VARIANT_ENUM_PARAMS(typename T), class Types>
struct is_variant_constructible_from< boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Types >:
boost::is_same<
typename boost::mpl::find_if<
typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::recursive_enabled_types,
mpl::not_< is_variant_constructible_from< boost::mpl::_1, Types> >
>::type,
typename boost::mpl::end< typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::recursive_enabled_types >::type
>
{};
template <BOOST_VARIANT_ENUM_PARAMS(typename T), class Types>
struct is_variant_constructible_from< const boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& , Types >:
is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Types >
{};
template <BOOST_VARIANT_ENUM_PARAMS(typename T), class Types>
struct is_variant_constructible_from< boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& , Types >:
is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Types >
{};
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <BOOST_VARIANT_ENUM_PARAMS(typename T), class Types>
struct is_variant_constructible_from< boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>&& , Types >:
is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Types >
{};
template <BOOST_VARIANT_ENUM_PARAMS(typename T), class Types>
struct is_variant_constructible_from< boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const && , Types >:
is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Types >
{};
#endif // #ifndef BOOST_NO_CXX11_RVALUE_REFERENCE
///////////////////////////////////////////////////////////////////////////////
// (detail) metafunction make_storage
//
// Provides an aligned storage type capable of holding any of the types
// specified in the given type-sequence.
//
template <typename Types, typename NeverUsesBackupFlag>
struct make_storage
{
private: // helpers, for metafunction result (below)
typedef typename mpl::eval_if<
NeverUsesBackupFlag
, mpl::identity< Types >
, mpl::push_front<
Types, backup_holder<void*>
>
>::type types;
typedef typename max_value<
types, mpl::sizeof_<mpl::_1>
>::type max_size;
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551))
typedef typename mpl::fold<
types
, mpl::size_t<1>
, add_alignment
>::type max_alignment;
#else // borland
// temporary workaround -- use maximal alignment
typedef mpl::size_t< -1 > max_alignment;
#endif // borland workaround
public: // metafunction result
typedef ::boost::aligned_storage<
BOOST_MPL_AUX_VALUE_WKND(max_size)::value
, BOOST_MPL_AUX_VALUE_WKND(max_alignment)::value
> type;
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class destroyer
//
// Internal visitor that destroys the value it visits.
//
struct destroyer
: public static_visitor<>
{
public: // visitor interfaces
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(T& operand, int) const BOOST_NOEXCEPT
{
operand.~T(); // must be noexcept
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551)) || \
BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
operand; // suppresses warnings
#endif
BOOST_VARIANT_AUX_RETURN_VOID;
}
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class template known_get
//
// Visitor that returns a reference to content of the specified type.
//
// Precondition: visited variant MUST contain logical content of type T.
//
template <typename T>
class known_get
: public static_visitor<T&>
{
public: // visitor interface
T& operator()(T& operand) const BOOST_NOEXCEPT
{
return operand;
}
template <typename U>
T& operator()(U&) const
{
// logical error to be here: see precondition above
return ::boost::detail::variant::forced_return< T& >();
}
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class copy_into
//
// Internal visitor that copies the value it visits into the given buffer.
//
class copy_into
: public static_visitor<>
{
private: // representation
void* storage_;
public: // structors
explicit copy_into(void* storage) BOOST_NOEXCEPT
: storage_(storage)
{
}
public: // internal visitor interface
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(boost::detail::variant::backup_holder<T>& operand, long) const
{
new(storage_) T( operand.get() );
BOOST_VARIANT_AUX_RETURN_VOID;
}
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(const boost::detail::variant::backup_holder<T>& operand, long) const
{
new(storage_) T( operand.get() );
BOOST_VARIANT_AUX_RETURN_VOID;
}
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(const T& operand, int) const
{
new(storage_) T(operand);
BOOST_VARIANT_AUX_RETURN_VOID;
}
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class move_into
//
// Internal visitor that moves the value it visits into the given buffer.
//
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
class move_into
: public static_visitor<>
{
private: // representation
void* storage_;
public: // structors
explicit move_into(void* storage) BOOST_NOEXCEPT
: storage_(storage)
{
}
public: // internal visitor interface
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(boost::detail::variant::backup_holder<T>& operand, long) const
{
new(storage_) T( ::boost::detail::variant::move(operand.get()) );
BOOST_VARIANT_AUX_RETURN_VOID;
}
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(T& operand, int) const BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(T(boost::declval<T>())))
{
new(storage_) T(::boost::detail::variant::move(operand));
BOOST_VARIANT_AUX_RETURN_VOID;
}
};
#endif
///////////////////////////////////////////////////////////////////////////////
// (detail) class assign_storage
//
// Internal visitor that assigns the given storage (which must be a
// constructed value of the same type) to the value it visits.
//
struct assign_storage
: public static_visitor<>
{
private: // representation
const void* rhs_storage_;
public: // structors
explicit assign_storage(const void* rhs_storage) BOOST_NOEXCEPT
: rhs_storage_(rhs_storage)
{
}
public: // internal visitor interfaces
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(backup_holder<T>& lhs_content, long) const
{
lhs_content.get()
= static_cast< const backup_holder<T>* >(rhs_storage_)->get();
BOOST_VARIANT_AUX_RETURN_VOID;
}
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(const backup_holder<T>& lhs_content, long) const
{
lhs_content.get()
= static_cast< const backup_holder<T>* >(rhs_storage_)->get();
BOOST_VARIANT_AUX_RETURN_VOID;
}
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(T& lhs_content, int) const
{
// NOTE TO USER :
// Compile error here indicates one of variant's bounded types does
// not meet the requirements of the Assignable concept. Thus,
// variant is not Assignable.
//
// Hint: Are any of the bounded types const-qualified or references?
//
lhs_content = *static_cast< const T* >(rhs_storage_);
BOOST_VARIANT_AUX_RETURN_VOID;
}
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class move_storage
//
// Internal visitor that moves the given storage (which must be a
// constructed value of the same type) to the value it visits.
//
struct move_storage
: public static_visitor<>
{
private: // representation
void* rhs_storage_;
public: // structors
explicit move_storage(void* rhs_storage) BOOST_NOEXCEPT
: rhs_storage_(rhs_storage)
{
}
public: // internal visitor interfaces
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(backup_holder<T>& lhs_content, long) const
{
lhs_content.get()
= ::boost::detail::variant::move(static_cast<backup_holder<T>* >(rhs_storage_)->get());
BOOST_VARIANT_AUX_RETURN_VOID;
}
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(const backup_holder<T>& lhs_content, long) const
{
lhs_content.get()
= ::boost::detail::variant::move(static_cast<backup_holder<T>* >(rhs_storage_)->get());
BOOST_VARIANT_AUX_RETURN_VOID;
}
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(T& lhs_content, int) const
{
// NOTE TO USER :
// Compile error here indicates one of variant's bounded types does
// not meet the requirements of the Assignable concept. Thus,
// variant is not Assignable.
//
// Hint: Are any of the bounded types const-qualified or references?
//
lhs_content = ::boost::detail::variant::move(*static_cast<T* >(rhs_storage_));
BOOST_VARIANT_AUX_RETURN_VOID;
}
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class direct_assigner
//
// Generic static visitor that: if and only if the visited value is of the
// specified type, assigns the given value to the visited value and returns
// true; else returns false.
//
template <typename T>
class direct_assigner
: public static_visitor<bool>
{
private: // representation
const T& rhs_;
public: // structors
explicit direct_assigner(const T& rhs) BOOST_NOEXCEPT
: rhs_(rhs)
{
}
public: // visitor interface
bool operator()(T& lhs)
{
lhs = rhs_;
return true;
}
template <typename U>
bool operator()(U&) BOOST_NOEXCEPT
{
return false;
}
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
private:
// silence MSVC warning C4512: assignment operator could not be generated
direct_assigner& operator= (direct_assigner const&);
#endif
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class direct_mover
//
// Generic static visitor that: if and only if the visited value is of the
// specified type, move assigns the given value to the visited value and returns
// true; else returns false.
//
template <typename T>
class direct_mover
: public static_visitor<bool>
{
private: // representation
T& rhs_;
public: // structors
explicit direct_mover(T& rhs) BOOST_NOEXCEPT
: rhs_(rhs)
{
}
public: // visitor interface
bool operator()(T& lhs)
{
lhs = ::boost::detail::variant::move(rhs_);
return true;
}
template <typename U>
bool operator()(U&) BOOST_NOEXCEPT
{
return false;
}
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
private:
// silence MSVC warning C4512: assignment operator could not be generated
direct_mover& operator= (direct_mover const&);
#endif
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class backup_assigner
//
// Internal visitor that "assigns" the given value to the visited value,
// using backup to recover if the destroy-copy sequence fails.
//
// NOTE: This needs to be a friend of variant, as it needs access to
// indicate_which, indicate_backup_which, etc.
//
template <typename Variant>
class backup_assigner
: public static_visitor<>
{
private: // representation
Variant& lhs_;
int rhs_which_;
const void* rhs_content_;
void (*copy_rhs_content_)(void*, const void*);
public: // structors
template<class RhsT>
backup_assigner(Variant& lhs, int rhs_which, const RhsT& rhs_content)
: lhs_(lhs)
, rhs_which_(rhs_which)
, rhs_content_(&rhs_content)
, copy_rhs_content_(&construct_impl<RhsT>)
{
}
private: // helpers, for visitor interface (below)
template<class RhsT>
static void construct_impl(void* addr, const void* obj)
{
new(addr) RhsT(*static_cast<const RhsT*>(obj));
}
template <typename LhsT>
void backup_assign_impl(
backup_holder<LhsT>& lhs_content
, mpl::false_ // is_nothrow_move_constructible
, long
)
{
// Move lhs content to backup...
backup_holder<LhsT> backup_lhs_content(0);
backup_lhs_content.swap(lhs_content); // nothrow
// ...destroy lhs content...
lhs_content.~backup_holder<LhsT>(); // nothrow
BOOST_TRY
{
// ...and attempt to copy rhs content into lhs storage:
copy_rhs_content_(lhs_.storage_.address(), rhs_content_);
}
BOOST_CATCH (...)
{
// In case of failure, copy backup pointer to lhs storage...
new(lhs_.storage_.address())
backup_holder<LhsT>( 0 ); // nothrow
static_cast<backup_holder<LhsT>* >(lhs_.storage_.address())
->swap(backup_lhs_content); // nothrow
// ...and rethrow:
BOOST_RETHROW;
}
BOOST_CATCH_END
// In case of success, indicate new content type:
lhs_.indicate_which(rhs_which_); // nothrow
}
template <typename LhsT>
void backup_assign_impl(
LhsT& lhs_content
, mpl::true_ // is_nothrow_move_constructible
, int
)
{
// Move lhs content to backup...
LhsT backup_lhs_content(
::boost::detail::variant::move(lhs_content)
); // nothrow
// ...destroy lhs content...
lhs_content.~LhsT(); // nothrow
BOOST_TRY
{
// ...and attempt to copy rhs content into lhs storage:
copy_rhs_content_(lhs_.storage_.address(), rhs_content_);
}
BOOST_CATCH (...)
{
// In case of failure, restore backup content to lhs storage...
new(lhs_.storage_.address())
LhsT(
::boost::detail::variant::move(backup_lhs_content)
); // nothrow
// ...and rethrow:
BOOST_RETHROW;
}
BOOST_CATCH_END
// In case of success, indicate new content type:
lhs_.indicate_which(rhs_which_); // nothrow
}
template <typename LhsT>
void backup_assign_impl(
LhsT& lhs_content
, mpl::false_ // is_nothrow_move_constructible
, int
)
{
// Backup lhs content...
LhsT* backup_lhs_ptr = new LhsT(lhs_content);
// ...destroy lhs content...
lhs_content.~LhsT(); // nothrow
BOOST_TRY
{
// ...and attempt to copy rhs content into lhs storage:
copy_rhs_content_(lhs_.storage_.address(), rhs_content_);
}
BOOST_CATCH (...)
{
// In case of failure, copy backup pointer to lhs storage...
new(lhs_.storage_.address())
backup_holder<LhsT>( backup_lhs_ptr ); // nothrow
// ...indicate now using backup...
lhs_.indicate_backup_which( lhs_.which() ); // nothrow
// ...and rethrow:
BOOST_RETHROW;
}
BOOST_CATCH_END
// In case of success, indicate new content type...
lhs_.indicate_which(rhs_which_); // nothrow
// ...and delete backup:
delete backup_lhs_ptr; // nothrow
}
public: // visitor interface
template <typename LhsT>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(LhsT& lhs_content, int)
{
typedef typename is_nothrow_move_constructible<LhsT>::type
nothrow_move;
backup_assign_impl( lhs_content, nothrow_move(), 1L);
BOOST_VARIANT_AUX_RETURN_VOID;
}
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
private:
// silence MSVC warning C4512: assignment operator could not be generated
backup_assigner& operator= (backup_assigner const&);
#endif
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class swap_with
//
// Visitor that swaps visited value with content of given variant.
//
// Precondition: Given variant MUST have same logical type as visited value.
//
template <typename Variant>
struct swap_with
: public static_visitor<>
{
private: // representation
Variant& toswap_;
public: // structors
explicit swap_with(Variant& toswap) BOOST_NOEXCEPT
: toswap_(toswap)
{
}
public: // internal visitor interfaces
template <typename T>
void operator()(T& operand) const
{
// Since the precondition ensures types are same, get T...
known_get<T> getter;
T& other = toswap_.apply_visitor(getter);
// ...and swap:
::boost::detail::variant::move_swap( operand, other );
}
private:
swap_with& operator=(const swap_with&);
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class reflect
//
// Generic static visitor that performs a typeid on the value it visits.
//
class reflect
: public static_visitor<const boost::typeindex::type_info&>
{
public: // visitor interfaces
template <typename T>
const boost::typeindex::type_info& operator()(const T&) const BOOST_NOEXCEPT
{
return boost::typeindex::type_id<T>().type_info();
}
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class comparer
//
// Generic static visitor that compares the content of the given lhs variant
// with the visited rhs content using Comp.
//
// Precondition: lhs.which() == rhs.which()
//
template <typename Variant, typename Comp>
class comparer
: public static_visitor<bool>
{
private: // representation
const Variant& lhs_;
public: // structors
explicit comparer(const Variant& lhs) BOOST_NOEXCEPT
: lhs_(lhs)
{
}
public: // visitor interfaces
template <typename T>
bool operator()(T& rhs_content) const
{
// Since the precondition ensures lhs and rhs types are same, get T...
known_get<T> getter;
const T& lhs_content = lhs_.apply_visitor(getter);
// ...and compare lhs and rhs contents:
return Comp()(lhs_content, rhs_content);
}
private:
comparer& operator=(const comparer&);
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class equal_comp
//
// Generic function object compares lhs with rhs using operator==.
//
struct equal_comp
{
template <typename T>
bool operator()(const T& lhs, const T& rhs) const
{
return lhs == rhs;
}
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class less_comp
//
// Generic function object compares lhs with rhs using operator<.
//
struct less_comp
{
template <typename T>
bool operator()(const T& lhs, const T& rhs) const
{
return lhs < rhs;
}
};
///////////////////////////////////////////////////////////////////////////////
// (detail) class template invoke_visitor
//
// Internal visitor that invokes the given visitor using:
// * for wrappers (e.g., recursive_wrapper), the wrapper's held value.
// * for all other values, the value itself.
//
template <typename Visitor>
class invoke_visitor
{
private: // representation
Visitor& visitor_;
public: // visitor typedefs
typedef typename Visitor::result_type
result_type;
public: // structors
explicit invoke_visitor(Visitor& visitor) BOOST_NOEXCEPT
: visitor_(visitor)
{
}
#if !defined(BOOST_NO_VOID_RETURNS)
public: // internal visitor interfaces
template <typename T>
result_type internal_visit(T& operand, int)
{
return visitor_(operand);
}
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0564))
template <typename T>
result_type internal_visit(const T& operand, int)
{
return visitor_(operand);
}
# endif
#else // defined(BOOST_NO_VOID_RETURNS)
private: // helpers, for internal visitor interfaces (below)
template <typename T>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
visit_impl(T& operand, mpl::false_)
{
return visitor_(operand);
}
template <typename T>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
visit_impl(T& operand, mpl::true_)
{
visitor_(operand);
BOOST_VARIANT_AUX_RETURN_VOID;
}
public: // internal visitor interfaces
template <typename T>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
internal_visit(T& operand, int)
{
typedef typename is_same<result_type, void>::type
has_void_result_type;
return visit_impl(operand, has_void_result_type());
}
#endif // BOOST_NO_VOID_RETURNS) workaround
public: // internal visitor interfaces, cont.
template <typename T>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
internal_visit(boost::recursive_wrapper<T>& operand, long)
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
internal_visit(const boost::recursive_wrapper<T>& operand, long)
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
internal_visit(boost::detail::reference_content<T>& operand, long)
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
internal_visit(const boost::detail::reference_content<T>& operand, long)
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
internal_visit(boost::detail::variant::backup_holder<T>& operand, long)
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
internal_visit(const boost::detail::variant::backup_holder<T>& operand, long)
{
return internal_visit( operand.get(), 1L );
}
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
private:
// silence MSVC warning C4512: assignment operator could not be generated
invoke_visitor& operator= (invoke_visitor const&);
#endif
};
}} // namespace detail::variant
///////////////////////////////////////////////////////////////////////////////
// class template variant (concept inspired by Andrei Alexandrescu)
//
// See docs and boost/variant/variant_fwd.hpp for more information.
//
template <
typename T0_
, BOOST_VARIANT_ENUM_SHIFTED_PARAMS(typename T)
>
class variant
{
private: // helpers, for typedefs (below)
typedef variant wknd_self_t;
struct is_recursive_
: detail::variant::is_recursive_flag<T0_>
{
};
typedef typename mpl::eval_if<
is_recursive_
, T0_
, mpl::identity< T0_ >
>::type unwrapped_T0_;
struct is_sequence_based_
: detail::variant::is_over_sequence<unwrapped_T0_>
{
};
#if !defined(BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT)
private: // helpers, for typedefs (below)
typedef typename mpl::eval_if<
is_sequence_based_
, unwrapped_T0_ // over_sequence<...>::type
, detail::variant::make_variant_list<
unwrapped_T0_
, BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T)
>
>::type specified_types;
BOOST_STATIC_ASSERT((
::boost::mpl::not_< mpl::empty<specified_types> >::value
));
public: // public typedefs
typedef typename mpl::eval_if<
is_recursive_
, mpl::transform<
specified_types
, mpl::protect<
detail::variant::quoted_enable_recursive<wknd_self_t>
>
>
, mpl::identity< specified_types >
>::type recursive_enabled_types; // used by is_variant_constructible_from<> trait
typedef typename mpl::transform<
recursive_enabled_types
, unwrap_recursive<mpl::_1>
>::type types;
private: // internal typedefs
typedef typename mpl::transform<
recursive_enabled_types
, mpl::protect< detail::make_reference_content<> >
>::type internal_types;
typedef typename mpl::front<
internal_types
>::type internal_T0;
#else // defined(BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT)
private: // helpers, for typedefs (below)
typedef unwrapped_T0_ T0;
#define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS(z,N,_) \
typedef typename mpl::eval_if< \
is_recursive_ \
, detail::variant::enable_recursive< \
BOOST_PP_CAT(T,N) \
, wknd_self_t \
> \
, mpl::identity< BOOST_PP_CAT(T,N) > \
>::type BOOST_PP_CAT(recursive_enabled_T,N); \
/**/
BOOST_PP_REPEAT(
BOOST_VARIANT_LIMIT_TYPES
, BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS
, _
)
#undef BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS
#define BOOST_VARIANT_AUX_UNWRAP_RECURSIVE_TYPEDEFS(z,N,_) \
typedef typename unwrap_recursive< \
BOOST_PP_CAT(recursive_enabled_T,N) \
>::type BOOST_PP_CAT(public_T,N); \
/**/
BOOST_PP_REPEAT(
BOOST_VARIANT_LIMIT_TYPES
, BOOST_VARIANT_AUX_UNWRAP_RECURSIVE_TYPEDEFS
, _
)
#undef BOOST_VARIANT_AUX_UNWRAP_RECURSIVE_TYPEDEFS
public: // public typedefs
typedef typename detail::variant::make_variant_list<
BOOST_VARIANT_ENUM_PARAMS(public_T)
>::type types;
private: // helpers, for internal typedefs (below)
#define BOOST_VARIANT_AUX_MAKE_REFERENCE_CONTENT_TYPEDEFS(z,N,_) \
typedef detail::make_reference_content< \
BOOST_PP_CAT(recursive_enabled_T,N) \
>::type BOOST_PP_CAT(internal_T,N); \
/**/
BOOST_PP_REPEAT(
BOOST_VARIANT_LIMIT_TYPES
, BOOST_VARIANT_AUX_MAKE_REFERENCE_CONTENT_TYPEDEFS
, _
)
#undef BOOST_VARIANT_AUX_MAKE_REFERENCE_CONTENT_TYPEDEFS
private: // internal typedefs
typedef typename detail::variant::make_variant_list<
BOOST_VARIANT_ENUM_PARAMS(internal_T)
>::type internal_types;
private: // static precondition assertions
// NOTE TO USER :
// variant< type-sequence > syntax is not supported on this compiler!
//
BOOST_MPL_ASSERT_NOT(( is_sequence_based_ ));
#endif // BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT workaround
private: // helpers, for representation (below)
typedef typename detail::variant::find_fallback_type<
internal_types
>::type fallback_type_result_;
typedef typename fallback_type_result_::first
fallback_type_index_;
typedef typename fallback_type_result_::second
fallback_type_;
struct has_fallback_type_
: mpl::not_<
is_same< fallback_type_, detail::variant::no_fallback_type >
>
{
};
typedef has_fallback_type_
never_uses_backup_flag;
typedef typename detail::variant::make_storage<
internal_types, never_uses_backup_flag
>::type storage_t;
#ifndef BOOST_NO_CXX11_NOEXCEPT
typedef typename detail::variant::is_variant_move_noexcept_constructible<
internal_types
> variant_move_noexcept_constructible;
typedef typename detail::variant::is_variant_move_noexcept_assignable<
internal_types
> variant_move_noexcept_assignable;
#endif
private: // helpers, for representation (below)
// which_ on:
// * [0, size<internal_types>) indicates stack content
// * [-size<internal_types>, 0) indicates pointer to heap backup
// if which_ >= 0:
// * then which() -> which_
// * else which() -> -(which_ + 1)
#if !defined(BOOST_VARIANT_MINIMIZE_SIZE)
typedef int which_t;
#else // defined(BOOST_VARIANT_MINIMIZE_SIZE)
// [if O1_size available, then attempt which_t size optimization...]
// [select signed char if fewer than SCHAR_MAX types, else signed int:]
typedef typename mpl::eval_if<
mpl::equal_to< mpl::O1_size<internal_types>, mpl::long_<-1> >
, mpl::identity< int >
, mpl::if_<
mpl::less< mpl::O1_size<internal_types>, mpl::int_<SCHAR_MAX> >
, signed char
, int
>
>::type which_t;
#endif // BOOST_VARIANT_MINIMIZE_SIZE switch
// representation -- private when possible
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
private:
#else
public:
#endif
which_t which_;
storage_t storage_;
void indicate_which(int which_arg) BOOST_NOEXCEPT
{
which_ = static_cast<which_t>( which_arg );
}
void indicate_backup_which(int which_arg) BOOST_NOEXCEPT
{
which_ = static_cast<which_t>( -(which_arg + 1) );
}
private: // helpers, for queries (below)
bool using_backup() const BOOST_NOEXCEPT
{
return which_ < 0;
}
public: // queries
int which() const BOOST_NOEXCEPT
{
// If using heap backup...
if (using_backup())
// ...then return adjusted which_:
return -(which_ + 1);
// Otherwise, return which_ directly:
return which_;
}
private: // helpers, for structors (below)
struct initializer
: BOOST_VARIANT_AUX_INITIALIZER_T(
recursive_enabled_types, recursive_enabled_T
)
{
};
void destroy_content() BOOST_NOEXCEPT
{
detail::variant::destroyer visitor;
this->internal_apply_visitor(visitor);
}
public: // structors
~variant() BOOST_NOEXCEPT
{
destroy_content();
}
variant()
#if !(defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x5130))
BOOST_NOEXCEPT_IF(boost::has_nothrow_constructor<internal_T0>::value)
#endif
{
#ifdef _MSC_VER
#pragma warning( push )
// behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
#pragma warning( disable : 4345 )
#endif
// NOTE TO USER :
// Compile error from here indicates that the first bound
// type is not default-constructible, and so variant cannot
// support its own default-construction.
//
new( storage_.address() ) internal_T0();
indicate_which(0); // zero is the index of the first bounded type
#ifdef _MSC_VER
#pragma warning( pop )
#endif
}
private: // helpers, for structors, cont. (below)
class convert_copy_into
: public static_visitor<int>
{
private: // representation
void* storage_;
public: // structors
explicit convert_copy_into(void* storage) BOOST_NOEXCEPT
: storage_(storage)
{
}
public: // internal visitor interfaces (below)
template <typename T>
int internal_visit(T& operand, int) const
{
// NOTE TO USER :
// Compile error here indicates one of the source variant's types
// cannot be unambiguously converted to the destination variant's
// types (or that no conversion exists).
//
return initializer::initialize(storage_, operand);
}
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0564))
template <typename T>
result_type internal_visit(const T& operand, int) const
{
return initializer::initialize(storage_, operand);
}
# endif
template <typename T>
int internal_visit(boost::detail::reference_content<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
int internal_visit(const boost::detail::reference_content<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
int internal_visit(boost::detail::variant::backup_holder<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
int internal_visit(const boost::detail::variant::backup_holder<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
int internal_visit(boost::recursive_wrapper<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
int internal_visit(const boost::recursive_wrapper<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
};
friend class convert_copy_into;
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
class convert_move_into
: public static_visitor<int>
{
private: // representation
void* storage_;
public: // structors
explicit convert_move_into(void* storage) BOOST_NOEXCEPT
: storage_(storage)
{
}
public: // internal visitor interfaces (below)
template <typename T>
int internal_visit(T& operand, int) const
{
// NOTE TO USER :
// Compile error here indicates one of the source variant's types
// cannot be unambiguously converted to the destination variant's
// types (or that no conversion exists).
//
return initializer::initialize(storage_, detail::variant::move(operand) );
}
template <typename T>
int internal_visit(boost::detail::reference_content<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
int internal_visit(const boost::detail::reference_content<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
int internal_visit(boost::detail::variant::backup_holder<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
int internal_visit(const boost::detail::variant::backup_holder<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
int internal_visit(boost::recursive_wrapper<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
template <typename T>
int internal_visit(const boost::recursive_wrapper<T>& operand, long) const
{
return internal_visit( operand.get(), 1L );
}
};
friend class convert_move_into;
#endif
private: // helpers, for structors, below
template <typename T>
void convert_construct(
T& operand
, int
, mpl::false_ = mpl::false_() // is_foreign_variant
)
{
// NOTE TO USER :
// Compile error here indicates that the given type is not
// unambiguously convertible to one of the variant's types
// (or that no conversion exists).
//
indicate_which(
initializer::initialize(
storage_.address()
, operand
)
);
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename T>
typename boost::enable_if<boost::is_rvalue_reference<T&&> >::type convert_construct(
T&& operand
, int
, mpl::false_ = mpl::false_() // is_foreign_variant
)
{
// NOTE TO USER :
// Compile error here indicates that the given type is not
// unambiguously convertible to one of the variant's types
// (or that no conversion exists).
//
indicate_which(
initializer::initialize(
storage_.address()
, detail::variant::move(operand)
)
);
}
#endif
template <typename Variant>
void convert_construct(
Variant& operand
, long
, mpl::true_// is_foreign_variant
)
{
convert_copy_into visitor(storage_.address());
indicate_which(
operand.internal_apply_visitor(visitor)
);
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename Variant>
typename boost::enable_if<boost::is_rvalue_reference<Variant&&> >::type convert_construct(
Variant&& operand
, long
, mpl::true_// is_foreign_variant
)
{
convert_move_into visitor(storage_.address());
indicate_which(
operand.internal_apply_visitor(visitor)
);
}
#endif
template <typename Variant>
void convert_construct_variant(Variant& operand)
{
// [Determine if the given variant is itself a bounded type, or if its
// content needs to be converted (i.e., it is a 'foreign' variant):]
//
typedef typename mpl::find_if<
types
, is_same<
add_const<mpl::_1>
, const Variant
>
>::type found_it;
typedef typename mpl::end<types>::type not_found;
typedef typename is_same<
found_it, not_found
>::type is_foreign_variant;
// Convert construct from operand:
convert_construct(
operand, 1L
, is_foreign_variant()
);
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename Variant>
typename boost::enable_if<boost::is_rvalue_reference<Variant&&> >::type convert_construct_variant(Variant&& operand)
{
// [Determine if the given variant is itself a bounded type, or if its
// content needs to be converted (i.e., it is a 'foreign' variant):]
//
typedef typename mpl::find_if<
types
, is_same<
add_const<mpl::_1>
, const Variant
>
>::type found_it;
typedef typename mpl::end<types>::type not_found;
typedef typename is_same<
found_it, not_found
>::type is_foreign_variant;
// Convert move construct from operand:
convert_construct(
detail::variant::move(operand), 1L
, is_foreign_variant()
);
}
#endif
template <BOOST_VARIANT_ENUM_PARAMS(typename U)>
typename boost::enable_if<mpl::or_<
boost::is_same<boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>, variant>,
boost::detail::variant::is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>&, internal_types>
> >::type convert_construct(
boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>& operand
, long
)
{
convert_construct_variant(operand);
}
template <BOOST_VARIANT_ENUM_PARAMS(typename U)>
typename boost::enable_if<mpl::or_<
boost::is_same<boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>, variant>,
boost::detail::variant::is_variant_constructible_from<const boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>&, internal_types>
> >::type convert_construct(
const boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>& operand
, long
)
{
convert_construct_variant(operand);
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <BOOST_VARIANT_ENUM_PARAMS(typename U)>
typename boost::enable_if<mpl::or_<
boost::is_same<boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>, variant>,
boost::detail::variant::is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>&&, internal_types>
> >::type convert_construct(
boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>&& operand
, long
)
{
convert_construct_variant( detail::variant::move(operand) );
}
#endif
public: // structors, cont.
template <typename T>
variant(const T& operand,
typename boost::enable_if<mpl::and_<
mpl::not_< boost::is_same<T, variant> >,
boost::detail::variant::is_variant_constructible_from<const T&, internal_types>
> >::type* = 0)
{
convert_construct(operand, 1L);
}
template <typename T>
variant(
T& operand
, typename boost::enable_if<mpl::and_<
mpl::not_< is_const<T> >,
mpl::not_< boost::is_same<T, variant> >,
boost::detail::variant::is_variant_constructible_from<T&, internal_types>
> >::type* = 0
)
{
convert_construct(operand, 1L);
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <class T>
variant(T&& operand,
typename boost::enable_if<mpl::and_<
boost::is_rvalue_reference<T&&>,
mpl::not_< boost::is_const<T> >,
mpl::not_< boost::is_same<T, variant> >,
boost::detail::variant::is_variant_constructible_from<T&&, internal_types>
> >::type* = 0)
{
convert_construct( detail::variant::move(operand), 1L);
}
#endif
public: // structors, cont.
// [MSVC6 requires copy constructor appear after template constructors]
variant(const variant& operand)
{
// Copy the value of operand into *this...
detail::variant::copy_into visitor( storage_.address() );
operand.internal_apply_visitor(visitor);
// ...and activate the *this's primary storage on success:
indicate_which(operand.which());
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
variant(variant&& operand) BOOST_NOEXCEPT_IF(variant_move_noexcept_constructible::type::value)
{
// Move the value of operand into *this...
detail::variant::move_into visitor( storage_.address() );
operand.internal_apply_visitor(visitor);
// ...and activate the *this's primary storage on success:
indicate_which(operand.which());
}
#endif
private: // helpers, for modifiers (below)
# if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template <typename Variant>
friend class detail::variant::backup_assigner;
# endif
// class assigner
//
// Internal visitor that "assigns" the visited value to the given variant
// by appropriate destruction and copy-construction.
//
class assigner
: public static_visitor<>
{
protected: // representation
variant& lhs_;
const int rhs_which_;
public: // structors
assigner(variant& lhs, int rhs_which) BOOST_NOEXCEPT
: lhs_(lhs)
, rhs_which_(rhs_which)
{
}
protected: // helpers, for internal visitor interface (below)
template <typename RhsT, typename B1, typename B2>
void assign_impl(
const RhsT& rhs_content
, mpl::true_ // has_nothrow_copy
, B1 // is_nothrow_move_constructible
, B2 // has_fallback_type
) const BOOST_NOEXCEPT
{
// Destroy lhs's content...
lhs_.destroy_content(); // nothrow
// ...copy rhs content into lhs's storage...
new(lhs_.storage_.address())
RhsT( rhs_content ); // nothrow
// ...and indicate new content type:
lhs_.indicate_which(rhs_which_); // nothrow
}
template <typename RhsT, typename B>
void assign_impl(
const RhsT& rhs_content
, mpl::false_ // has_nothrow_copy
, mpl::true_ // is_nothrow_move_constructible
, B // has_fallback_type
) const
{
// Attempt to make a temporary copy (so as to move it below)...
RhsT temp(rhs_content);
// ...and upon success destroy lhs's content...
lhs_.destroy_content(); // nothrow
// ...move the temporary copy into lhs's storage...
new(lhs_.storage_.address())
RhsT( detail::variant::move(temp) ); // nothrow
// ...and indicate new content type:
lhs_.indicate_which(rhs_which_); // nothrow
}
void construct_fallback() const BOOST_NOEXCEPT {
// In case of failure, default-construct fallback type in lhs's storage...
new (lhs_.storage_.address())
fallback_type_; // nothrow
// ...indicate construction of fallback type...
lhs_.indicate_which(
BOOST_MPL_AUX_VALUE_WKND(fallback_type_index_)::value
); // nothrow
}
template <typename RhsT>
void assign_impl(
const RhsT& rhs_content
, mpl::false_ // has_nothrow_copy
, mpl::false_ // is_nothrow_move_constructible
, mpl::true_ // has_fallback_type
) const
{
// Destroy lhs's content...
lhs_.destroy_content(); // nothrow
BOOST_TRY
{
// ...and attempt to copy rhs's content into lhs's storage:
new(lhs_.storage_.address())
RhsT( rhs_content );
}
BOOST_CATCH (...)
{
construct_fallback();
// ...and rethrow:
BOOST_RETHROW;
}
BOOST_CATCH_END
// In the event of success, indicate new content type:
lhs_.indicate_which(rhs_which_); // nothrow
}
template <typename RhsT>
void assign_impl(
const RhsT& rhs_content
, mpl::false_ // has_nothrow_copy
, mpl::false_ // is_nothrow_move_constructible
, mpl::false_ // has_fallback_type
) const
{
detail::variant::backup_assigner<wknd_self_t>
visitor(lhs_, rhs_which_, rhs_content);
lhs_.internal_apply_visitor(visitor);
}
public: // internal visitor interfaces
template <typename RhsT>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(const RhsT& rhs_content, int) const
{
typedef typename has_nothrow_copy<RhsT>::type
nothrow_copy;
typedef typename mpl::or_< // reduces compile-time
nothrow_copy
, is_nothrow_move_constructible<RhsT>
>::type nothrow_move_constructor;
assign_impl(
rhs_content
, nothrow_copy()
, nothrow_move_constructor()
, has_fallback_type_()
);
BOOST_VARIANT_AUX_RETURN_VOID;
}
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
private:
// silence MSVC warning C4512: assignment operator could not be generated
assigner& operator= (assigner const&);
#endif
};
friend class assigner;
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
// class move_assigner
//
// Internal visitor that "move assigns" the visited value to the given variant
// by appropriate destruction and move-construction.
//
class move_assigner
: public assigner
{
public: // structors
move_assigner(variant& lhs, int rhs_which) BOOST_NOEXCEPT
: assigner(lhs, rhs_which)
{
}
private: // helpers, for internal visitor interface (below)
template <typename RhsT, typename B2>
void assign_impl(
RhsT& rhs_content
, mpl::true_ // has_nothrow_copy
, mpl::false_ // is_nothrow_move_constructible
, B2 // has_fallback_type
) const BOOST_NOEXCEPT
{
assigner::assign_impl(rhs_content, mpl::true_(), mpl::false_(), B2());
}
template <typename RhsT, typename B, typename B2>
void assign_impl(
RhsT& rhs_content
, B // has_nothrow_copy
, mpl::true_ // is_nothrow_move_constructible
, B2 // has_fallback_type
) const BOOST_NOEXCEPT
{
// ...destroy lhs's content...
assigner::lhs_.destroy_content(); // nothrow
// ...move the rhs_content into lhs's storage...
new(assigner::lhs_.storage_.address())
RhsT( detail::variant::move(rhs_content) ); // nothrow
// ...and indicate new content type:
assigner::lhs_.indicate_which(assigner::rhs_which_); // nothrow
}
template <typename RhsT>
void assign_impl(
RhsT& rhs_content
, mpl::false_ // has_nothrow_copy
, mpl::false_ // is_nothrow_move_constructible
, mpl::true_ // has_fallback_type
) const
{
// Destroy lhs's content...
assigner::lhs_.destroy_content(); // nothrow
BOOST_TRY
{
// ...and attempt to copy rhs's content into lhs's storage:
new(assigner::lhs_.storage_.address())
RhsT( detail::variant::move(rhs_content) );
}
BOOST_CATCH (...)
{
assigner::construct_fallback();
// ...and rethrow:
BOOST_RETHROW;
}
BOOST_CATCH_END
// In the event of success, indicate new content type:
assigner::lhs_.indicate_which(assigner::rhs_which_); // nothrow
}
template <typename RhsT>
void assign_impl(
RhsT& rhs_content
, mpl::false_ // has_nothrow_copy
, mpl::false_ // is_nothrow_move_constructible
, mpl::false_ // has_fallback_type
) const
{
assigner::assign_impl(rhs_content, mpl::false_(), mpl::false_(), mpl::false_());
}
public: // internal visitor interfaces
template <typename RhsT>
BOOST_VARIANT_AUX_RETURN_VOID_TYPE
internal_visit(RhsT& rhs_content, int) const
{
typedef typename is_nothrow_move_constructible<RhsT>::type
nothrow_move_constructor;
typedef typename mpl::or_< // reduces compile-time
nothrow_move_constructor
, has_nothrow_copy<RhsT>
>::type nothrow_copy;
assign_impl(
rhs_content
, nothrow_copy()
, nothrow_move_constructor()
, has_fallback_type_()
);
BOOST_VARIANT_AUX_RETURN_VOID;
}
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
private:
// silence MSVC warning C4512: assignment operator could not be generated
move_assigner& operator= (move_assigner const&);
#endif
};
friend class move_assigner;
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
void variant_assign(const variant& rhs)
{
// If the contained types are EXACTLY the same...
if (which_ == rhs.which_)
{
// ...then assign rhs's storage to lhs's content:
detail::variant::assign_storage visitor(rhs.storage_.address());
this->internal_apply_visitor(visitor);
}
else
{
// Otherwise, perform general (copy-based) variant assignment:
assigner visitor(*this, rhs.which());
rhs.internal_apply_visitor(visitor);
}
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
void variant_assign(variant&& rhs)
{
// If the contained types are EXACTLY the same...
if (which_ == rhs.which_)
{
// ...then move rhs's storage to lhs's content:
detail::variant::move_storage visitor(rhs.storage_.address());
this->internal_apply_visitor(visitor);
}
else
{
// Otherwise, perform general (move-based) variant assignment:
move_assigner visitor(*this, rhs.which());
rhs.internal_apply_visitor(visitor);
}
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
private: // helpers, for modifiers (below)
template <typename T>
void assign(const T& rhs)
{
// If direct T-to-T assignment is not possible...
detail::variant::direct_assigner<T> direct_assign(rhs);
if (this->apply_visitor(direct_assign) == false)
{
// ...then convert rhs to variant and assign:
//
// While potentially inefficient, the following construction of a
// variant allows T as any type convertible to one of the bounded
// types without excessive code redundancy.
//
variant temp(rhs);
variant_assign( detail::variant::move(temp) );
}
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename T>
void move_assign(T&& rhs)
{
// If direct T-to-T move assignment is not possible...
detail::variant::direct_mover<T> direct_move(rhs);
if (this->apply_visitor(direct_move) == false)
{
// ...then convert rhs to variant and assign:
//
// While potentially inefficient, the following construction of a
// variant allows T as any type convertible to one of the bounded
// types without excessive code redundancy.
//
variant temp( detail::variant::move(rhs) );
variant_assign( detail::variant::move(temp) );
}
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
public: // modifiers
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
template <class T>
typename boost::enable_if<
boost::mpl::and_<
boost::is_rvalue_reference<T&&>,
mpl::not_< boost::is_const<T> >,
boost::detail::variant::is_variant_constructible_from<T&&, internal_types>
>,
variant&
>::type operator=(T&& rhs)
{
move_assign( detail::variant::move(rhs) );
return *this;
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
template <typename T>
typename boost::enable_if<
mpl::or_<
boost::is_same<T, variant>,
boost::detail::variant::is_variant_constructible_from<const T&, internal_types>
>,
variant&
>::type operator=(const T& rhs)
{
assign(rhs);
return *this;
}
// [MSVC6 requires copy assign appear after templated operator=]
variant& operator=(const variant& rhs)
{
variant_assign(rhs);
return *this;
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
variant& operator=(variant&& rhs)
#if !defined(__GNUC__) || (__GNUC__ != 4) || (__GNUC_MINOR__ > 6) || defined(__clang__)
BOOST_NOEXCEPT_IF(variant_move_noexcept_constructible::type::value && variant_move_noexcept_assignable::type::value)
#endif
{
variant_assign( detail::variant::move(rhs) );
return *this;
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
void swap(variant& rhs)
{
// If the contained types are the same...
if (which() == rhs.which())
{
// ...then swap the values directly:
detail::variant::swap_with<variant> visitor(rhs);
this->apply_visitor(visitor);
}
else
{
// ...otherwise, perform general variant swap:
variant tmp( detail::variant::move(rhs) );
rhs = detail::variant::move(*this);
*this = detail::variant::move(tmp);
}
}
public: // queries
//
// NOTE: member which() defined above.
//
bool empty() const BOOST_NOEXCEPT
{
return false;
}
const boost::typeindex::type_info& type() const
{
detail::variant::reflect visitor;
return this->apply_visitor(visitor);
}
public: // prevent comparison with foreign types
template <typename U>
void operator==(const U&) const
{
BOOST_STATIC_ASSERT( false && sizeof(U) );
}
template <typename U>
void operator<(const U&) const
{
BOOST_STATIC_ASSERT( false && sizeof(U) );
}
template <typename U>
void operator!=(const U&) const
{
BOOST_STATIC_ASSERT( false && sizeof(U) );
}
template <typename U>
void operator>(const U&) const
{
BOOST_STATIC_ASSERT( false && sizeof(U) );
}
template <typename U>
void operator<=(const U&) const
{
BOOST_STATIC_ASSERT( false && sizeof(U) );
}
template <typename U>
void operator>=(const U&) const
{
BOOST_STATIC_ASSERT( false && sizeof(U) );
}
public: // comparison operators
// [MSVC6 requires these operators appear after template operators]
bool operator==(const variant& rhs) const
{
if (this->which() != rhs.which())
return false;
detail::variant::comparer<
variant, detail::variant::equal_comp
> visitor(*this);
return rhs.apply_visitor(visitor);
}
bool operator<(const variant& rhs) const
{
//
// Dirk Schreib suggested this collating order.
//
if (this->which() != rhs.which())
return this->which() < rhs.which();
detail::variant::comparer<
variant, detail::variant::less_comp
> visitor(*this);
return rhs.apply_visitor(visitor);
}
///////////////////////////////////////////////////////////////////////////////
// comparison operators != > <= >=
inline bool operator!=(const variant& rhs) const
{
return !(*this == rhs);
}
inline bool operator>(const variant& rhs) const
{
return rhs < *this;
}
inline bool operator<=(const variant& rhs) const
{
return !(*this > rhs);
}
inline bool operator>=(const variant& rhs) const
{
return !(*this < rhs);
}
// helpers, for visitation support (below) -- private when possible
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template < BOOST_VARIANT_ENUM_PARAMS(typename U) >
friend class variant;
private:
#else// defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
public:
#endif// !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
template <typename Visitor, typename VoidPtrCV>
static
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(
typename Visitor::result_type
)
internal_apply_visitor_impl(
int internal_which
, int logical_which
, Visitor& visitor
, VoidPtrCV storage
)
{
typedef mpl::int_<0> first_which;
typedef typename mpl::begin<internal_types>::type first_it;
typedef typename mpl::end<internal_types>::type last_it;
typedef detail::variant::visitation_impl_step<
first_it, last_it
> first_step;
return detail::variant::visitation_impl(
internal_which, logical_which
, visitor, storage, mpl::false_()
, never_uses_backup_flag()
, static_cast<first_which*>(0), static_cast<first_step*>(0)
);
}
template <typename Visitor>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(
typename Visitor::result_type
)
internal_apply_visitor(Visitor& visitor)
{
return internal_apply_visitor_impl(
which_, which(), visitor, storage_.address()
);
}
template <typename Visitor>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(
typename Visitor::result_type
)
internal_apply_visitor(Visitor& visitor) const
{
return internal_apply_visitor_impl(
which_, which(), visitor, storage_.address()
);
}
public: // visitation support
template <typename Visitor>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(
typename Visitor::result_type
)
apply_visitor(Visitor& visitor)
{
detail::variant::invoke_visitor<Visitor> invoker(visitor);
return this->internal_apply_visitor(invoker);
}
template <typename Visitor>
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(
typename Visitor::result_type
)
apply_visitor(Visitor& visitor) const
{
detail::variant::invoke_visitor<Visitor> invoker(visitor);
return this->internal_apply_visitor(invoker);
}
}; // class variant
///////////////////////////////////////////////////////////////////////////////
// metafunction make_variant_over
//
// See docs and boost/variant/variant_fwd.hpp for more information.
//
template <typename Types>
struct make_variant_over
{
private: // precondition assertions
BOOST_STATIC_ASSERT(( ::boost::mpl::is_sequence<Types>::value ));
public: // metafunction result
typedef variant<
detail::variant::over_sequence< Types >
> type;
};
///////////////////////////////////////////////////////////////////////////////
// function template swap
//
// Swaps two variants of the same type (i.e., identical specification).
//
template < BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline void swap(
variant< BOOST_VARIANT_ENUM_PARAMS(T) >& lhs
, variant< BOOST_VARIANT_ENUM_PARAMS(T) >& rhs
)
{
lhs.swap(rhs);
}
} // namespace boost
// implementation additions
#if !defined(BOOST_NO_IOSTREAM)
#include <boost/variant/detail/variant_io.hpp>
#endif // BOOST_NO_IOSTREAM
#endif // BOOST_VARIANT_VARIANT_HPP
|