1302 typedef detail::helper< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 > helper_type;
1303 typedef variant_TL16( T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 ) variant_types;
1308 variant() : type_index( 0 ) {
new( ptr() ) T0(); }
1310#if variant_CPP11_OR_GREATER
1313 variant( T0
const & t0 ) : type_index( 0 ) {
new( ptr() ) T0( t0 ); }
1317 variant( T1
const & t1 ) : type_index( 1 ) {
new( ptr() ) T1( t1 ); }
1321 variant( T2
const & t2 ) : type_index( 2 ) {
new( ptr() ) T2( t2 ); }
1325 variant( T3
const & t3 ) : type_index( 3 ) {
new( ptr() )
T3( t3 ); }
1329 variant( T4
const & t4 ) : type_index( 4 ) {
new( ptr() )
T4( t4 ); }
1333 variant( T5
const & t5 ) : type_index( 5 ) {
new( ptr() )
T5( t5 ); }
1337 variant( T6
const & t6 ) : type_index( 6 ) {
new( ptr() )
T6( t6 ); }
1341 variant( T7
const & t7 ) : type_index( 7 ) {
new( ptr() )
T7( t7 ); }
1345 variant( T8
const & t8 ) : type_index( 8 ) {
new( ptr() )
T8( t8 ); }
1349 variant( T9
const & t9 ) : type_index( 9 ) {
new( ptr() )
T9( t9 ); }
1353 variant( T10
const & t10 ) : type_index( 10 ) {
new( ptr() )
T10( t10 ); }
1357 variant( T11
const & t11 ) : type_index( 11 ) {
new( ptr() )
T11( t11 ); }
1361 variant( T12
const & t12 ) : type_index( 12 ) {
new( ptr() )
T12( t12 ); }
1365 variant( T13
const & t13 ) : type_index( 13 ) {
new( ptr() )
T13( t13 ); }
1369 variant( T14
const & t14 ) : type_index( 14 ) {
new( ptr() )
T14( t14 ); }
1373 variant( T15
const & t15 ) : type_index( 15 ) {
new( ptr() )
T15( t15 ); }
1377 variant( T0
const & t0 ) : type_index( 0 ) {
new( ptr() ) T0( t0 ); }
1378 variant( T1
const & t1 ) : type_index( 1 ) {
new( ptr() ) T1( t1 ); }
1379 variant( T2
const & t2 ) : type_index( 2 ) {
new( ptr() ) T2( t2 ); }
1380 variant( T3
const & t3 ) : type_index( 3 ) {
new( ptr() ) T3( t3 ); }
1381 variant( T4
const & t4 ) : type_index( 4 ) {
new( ptr() ) T4( t4 ); }
1382 variant( T5
const & t5 ) : type_index( 5 ) {
new( ptr() ) T5( t5 ); }
1383 variant( T6
const & t6 ) : type_index( 6 ) {
new( ptr() ) T6( t6 ); }
1384 variant( T7
const & t7 ) : type_index( 7 ) {
new( ptr() ) T7( t7 ); }
1385 variant( T8
const & t8 ) : type_index( 8 ) {
new( ptr() ) T8( t8 ); }
1386 variant( T9
const & t9 ) : type_index( 9 ) {
new( ptr() ) T9( t9 ); }
1387 variant( T10
const & t10 ) : type_index( 10 ) {
new( ptr() ) T10( t10 ); }
1388 variant( T11
const & t11 ) : type_index( 11 ) {
new( ptr() ) T11( t11 ); }
1389 variant( T12
const & t12 ) : type_index( 12 ) {
new( ptr() ) T12( t12 ); }
1390 variant( T13
const & t13 ) : type_index( 13 ) {
new( ptr() ) T13( t13 ); }
1391 variant( T14
const & t14 ) : type_index( 14 ) {
new( ptr() ) T14( t14 ); }
1392 variant( T15
const & t15 ) : type_index( 15 ) {
new( ptr() ) T15( t15 ); }
1396#if variant_CPP11_OR_GREATER
1400 : type_index( 0 ) {
new( ptr() ) T0( std::move(t0) ); }
1405 : type_index( 1 ) {
new( ptr() ) T1( std::move(t1) ); }
1410 : type_index( 2 ) {
new( ptr() ) T2( std::move(t2) ); }
1415 : type_index( 3 ) {
new( ptr() )
T3( std::move(t3) ); }
1420 : type_index( 4 ) {
new( ptr() )
T4( std::move(t4) ); }
1425 : type_index( 5 ) {
new( ptr() )
T5( std::move(t5) ); }
1430 : type_index( 6 ) {
new( ptr() )
T6( std::move(t6) ); }
1435 : type_index( 7 ) {
new( ptr() )
T7( std::move(t7) ); }
1440 : type_index( 8 ) {
new( ptr() )
T8( std::move(t8) ); }
1445 : type_index( 9 ) {
new( ptr() )
T9( std::move(t9) ); }
1449 variant( T10 && t10 )
1450 : type_index( 10 ) {
new( ptr() )
T10( std::move(t10) ); }
1454 variant( T11 && t11 )
1455 : type_index( 11 ) {
new( ptr() )
T11( std::move(t11) ); }
1459 variant( T12 && t12 )
1460 : type_index( 12 ) {
new( ptr() )
T12( std::move(t12) ); }
1464 variant( T13 && t13 )
1465 : type_index( 13 ) {
new( ptr() )
T13( std::move(t13) ); }
1469 variant( T14 && t14 )
1470 : type_index( 14 ) {
new( ptr() )
T14( std::move(t14) ); }
1474 variant( T15 && t15 )
1475 : type_index( 15 ) {
new( ptr() )
T15( std::move(t15) ); }
1479 : type_index( other.type_index )
1481 (void) helper_type::copy_construct( other.
type_index, other.
ptr(), ptr() );
1484#if variant_CPP11_OR_GREATER
1487 std::is_nothrow_move_constructible<T0>::value &&
1488 std::is_nothrow_move_constructible<T1>::value &&
1489 std::is_nothrow_move_constructible<T2>::value &&
1490 std::is_nothrow_move_constructible<T3>::value &&
1491 std::is_nothrow_move_constructible<T4>::value &&
1492 std::is_nothrow_move_constructible<T5>::value &&
1493 std::is_nothrow_move_constructible<T6>::value &&
1494 std::is_nothrow_move_constructible<T7>::value &&
1495 std::is_nothrow_move_constructible<T8>::value &&
1496 std::is_nothrow_move_constructible<T9>::value &&
1497 std::is_nothrow_move_constructible<T10>::value &&
1498 std::is_nothrow_move_constructible<T11>::value &&
1499 std::is_nothrow_move_constructible<T12>::value &&
1500 std::is_nothrow_move_constructible<T13>::value &&
1501 std::is_nothrow_move_constructible<T14>::value &&
1502 std::is_nothrow_move_constructible<T15>::value)
1503 : type_index( other.type_index )
1505 (void) helper_type::move_construct( other.type_index, other.ptr(), ptr() );
1508 template< std::
size_t K >
1509 using type_at_t =
typename detail::typelist_type_at< variant_types, K >::type;
1511 template<
class T,
class... Args
1512 variant_REQUIRES_T( std::is_constructible< T, Args...>::value )
1516 type_index = variant_npos_internal();
1517 type_index = helper_type::template construct_t<T>( ptr(), std::forward<Args>(args)... );
1520 template<
class T,
class U,
class... Args
1521 variant_REQUIRES_T( std::is_constructible< T, std::initializer_list<U>&, Args...>::value )
1525 type_index = variant_npos_internal();
1526 type_index = helper_type::template construct_t<T>( ptr(), il, std::forward<Args>(args)... );
1529 template< std::size_t K,
class... Args
1530 variant_REQUIRES_T( std::is_constructible< type_at_t<K>, Args...>::value )
1534 type_index = variant_npos_internal();
1535 type_index = helper_type::template construct_i<K>( ptr(), std::forward<Args>(args)... );
1538 template<
size_t K,
class U,
class... Args
1539 variant_REQUIRES_T( std::is_constructible< type_at_t<K>, std::initializer_list<U>&, Args...>::value )
1543 type_index = variant_npos_internal();
1544 type_index = helper_type::template construct_i<K>( ptr(), il, std::forward<Args>(args)... );
1553 if ( ! valueless_by_exception() )
1555 helper_type::destroy( type_index, ptr() );
1563 return copy_assign( other );
1566#if variant_CPP11_OR_GREATER
1569 std::is_nothrow_move_assignable<T0>::value &&
1570 std::is_nothrow_move_assignable<T1>::value &&
1571 std::is_nothrow_move_assignable<T2>::value &&
1572 std::is_nothrow_move_assignable<T3>::value &&
1573 std::is_nothrow_move_assignable<T4>::value &&
1574 std::is_nothrow_move_assignable<T5>::value &&
1575 std::is_nothrow_move_assignable<T6>::value &&
1576 std::is_nothrow_move_assignable<T7>::value &&
1577 std::is_nothrow_move_assignable<T8>::value &&
1578 std::is_nothrow_move_assignable<T9>::value &&
1579 std::is_nothrow_move_assignable<T10>::value &&
1580 std::is_nothrow_move_assignable<T11>::value &&
1581 std::is_nothrow_move_assignable<T12>::value &&
1582 std::is_nothrow_move_assignable<T13>::value &&
1583 std::is_nothrow_move_assignable<T14>::value &&
1584 std::is_nothrow_move_assignable<T15>::value)
1586 return move_assign( std::move( other ) );
1591 variant & operator=( T0 && t0 ) {
return assign_value<0>( std::move( t0 ) ); }
1595 variant & operator=( T1 && t1 ) {
return assign_value<1>( std::move( t1 ) ); }
1599 variant & operator=( T2 && t2 ) {
return assign_value<2>( std::move( t2 ) ); }
1603 variant & operator=( T3 && t3 ) {
return assign_value<3>( std::move( t3 ) ); }
1607 variant & operator=( T4 && t4 ) {
return assign_value<4>( std::move( t4 ) ); }
1611 variant & operator=( T5 && t5 ) {
return assign_value<5>( std::move( t5 ) ); }
1615 variant & operator=( T6 && t6 ) {
return assign_value<6>( std::move( t6 ) ); }
1619 variant & operator=( T7 && t7 ) {
return assign_value<7>( std::move( t7 ) ); }
1623 variant & operator=( T8 && t8 ) {
return assign_value<8>( std::move( t8 ) ); }
1627 variant & operator=( T9 && t9 ) {
return assign_value<9>( std::move( t9 ) ); }
1631 variant & operator=( T10 && t10 ) {
return assign_value<10>( std::move( t10 ) ); }
1635 variant & operator=( T11 && t11 ) {
return assign_value<11>( std::move( t11 ) ); }
1639 variant & operator=( T12 && t12 ) {
return assign_value<12>( std::move( t12 ) ); }
1643 variant & operator=( T13 && t13 ) {
return assign_value<13>( std::move( t13 ) ); }
1647 variant & operator=( T14 && t14 ) {
return assign_value<14>( std::move( t14 ) ); }
1651 variant & operator=( T15 && t15 ) {
return assign_value<15>( std::move( t15 ) ); }
1655#if variant_CPP11_OR_GREATER
1659 variant & operator=( T0
const & t0 ) {
return assign_value<0>( t0 ); }
1663 variant & operator=( T1
const & t1 ) {
return assign_value<1>( t1 ); }
1667 variant & operator=( T2
const & t2 ) {
return assign_value<2>( t2 ); }
1671 variant & operator=( T3
const & t3 ) {
return assign_value<3>( t3 ); }
1675 variant & operator=( T4
const & t4 ) {
return assign_value<4>( t4 ); }
1679 variant & operator=( T5
const & t5 ) {
return assign_value<5>( t5 ); }
1683 variant & operator=( T6
const & t6 ) {
return assign_value<6>( t6 ); }
1687 variant & operator=( T7
const & t7 ) {
return assign_value<7>( t7 ); }
1691 variant & operator=( T8
const & t8 ) {
return assign_value<8>( t8 ); }
1695 variant & operator=( T9
const & t9 ) {
return assign_value<9>( t9 ); }
1699 variant & operator=( T10
const & t10 ) {
return assign_value<10>( t10 ); }
1703 variant & operator=( T11
const & t11 ) {
return assign_value<11>( t11 ); }
1707 variant & operator=( T12
const & t12 ) {
return assign_value<12>( t12 ); }
1711 variant & operator=( T13
const & t13 ) {
return assign_value<13>( t13 ); }
1715 variant & operator=( T14
const & t14 ) {
return assign_value<14>( t14 ); }
1719 variant & operator=( T15
const & t15 ) {
return assign_value<15>( t15 ); }
1744 return variant_npos_internal() == type_index ? variant_npos :
static_cast<std::size_t
>( type_index );
1749#if variant_CPP11_OR_GREATER
1751 template<
class T,
class... Args
1752 variant_REQUIRES_T( std::is_constructible< T, Args...>::value )
1755 T& emplace( Args&&... args )
1757 helper_type::destroy( type_index, ptr() );
1758 type_index = variant_npos_internal();
1759 type_index = helper_type::template construct_t<T>( ptr(), std::forward<Args>(args)... );
1764 template<
class T,
class U,
class... Args
1765 variant_REQUIRES_T( std::is_constructible< T, std::initializer_list<U>&, Args...>::value )
1766 variant_REQUIRES_T( detail::typelist_contains_unique_type< variant_types, T >::value )
1768 T& emplace( std::initializer_list<U> il, Args&&... args )
1770 helper_type::destroy( type_index, ptr() );
1771 type_index = variant_npos_internal();
1772 type_index = helper_type::template construct_t<T>( ptr(), il, std::forward<Args>(args)... );
1777 template<
size_t K,
class... Args
1778 variant_REQUIRES_T( std::is_constructible< type_at_t<K>, Args...>::value )
1780 variant_alternative_t<K, variant> & emplace( Args&&... args )
1782 return this->
template emplace< type_at_t<K> >( std::forward<Args>(args)... );
1785 template<
size_t K,
class U,
class... Args
1786 variant_REQUIRES_T( std::is_constructible< type_at_t<K>, std::initializer_list<U>&, Args...>::value )
1788 variant_alternative_t<K, variant> & emplace( std::initializer_list<U> il, Args&&... args )
1790 return this->
template emplace< type_at_t<K> >( il, std::forward<Args>(args)... );
1799 return type_index == variant_npos_internal();
1805#if variant_CPP11_OR_GREATER
1807 std::is_nothrow_move_constructible<T0>::value && std17::is_nothrow_swappable<T0>::value &&
1808 std::is_nothrow_move_constructible<T1>::value && std17::is_nothrow_swappable<T1>::value &&
1809 std::is_nothrow_move_constructible<T2>::value && std17::is_nothrow_swappable<T2>::value &&
1810 std::is_nothrow_move_constructible<T3>::value && std17::is_nothrow_swappable<T3>::value &&
1811 std::is_nothrow_move_constructible<T4>::value && std17::is_nothrow_swappable<T4>::value &&
1812 std::is_nothrow_move_constructible<T5>::value && std17::is_nothrow_swappable<T5>::value &&
1813 std::is_nothrow_move_constructible<T6>::value && std17::is_nothrow_swappable<T6>::value &&
1814 std::is_nothrow_move_constructible<T7>::value && std17::is_nothrow_swappable<T7>::value &&
1815 std::is_nothrow_move_constructible<T8>::value && std17::is_nothrow_swappable<T8>::value &&
1816 std::is_nothrow_move_constructible<T9>::value && std17::is_nothrow_swappable<T9>::value &&
1817 std::is_nothrow_move_constructible<T10>::value && std17::is_nothrow_swappable<T10>::value &&
1818 std::is_nothrow_move_constructible<T11>::value && std17::is_nothrow_swappable<T11>::value &&
1819 std::is_nothrow_move_constructible<T12>::value && std17::is_nothrow_swappable<T12>::value &&
1820 std::is_nothrow_move_constructible<T13>::value && std17::is_nothrow_swappable<T13>::value &&
1821 std::is_nothrow_move_constructible<T14>::value && std17::is_nothrow_swappable<T14>::value &&
1822 std::is_nothrow_move_constructible<T15>::value && std17::is_nothrow_swappable<T15>::value
1833 this->swap_value( type_index, other );
1837#if variant_CPP11_OR_GREATER
1838 variant tmp( std::move( *
this ) );
1839 *
this = std::move( other );
1840 other = std::move( tmp );
1862#if variant_CONFIG_NO_EXCEPTIONS
1863 assert( index_of<T>() == index() );
1865 if ( index_of<T>() != index() )
1867 throw bad_variant_access();
1876#if variant_CONFIG_NO_EXCEPTIONS
1877 assert( index_of<T>() == index() );
1879 if ( index_of<T>() != index() )
1881 throw bad_variant_access();
1884 return *as<const T>();
1887 template< std::
size_t K >
1891 return this->
template get< typename detail::typelist_type_at< variant_types, K >::type >();
1894 template< std::
size_t K >
1898 return this->
template get< typename detail::typelist_type_at< variant_types, K >::type >();
1917 return reinterpret_cast<U*
>( ptr() );
1923 return reinterpret_cast<U
const *
>( ptr() );
1929 return static_cast<std::size_t
>( index );
1945 helper_type::destroy( type_index, ptr() );
1946 type_index = variant_npos_internal();
1948 else if ( index() == other.
index() )
1950 type_index = helper_type::copy_assign( other.
type_index, other.
ptr(), ptr() );
1954 helper_type::destroy( type_index, ptr() );
1955 type_index = variant_npos_internal();
1956 type_index = helper_type::copy_construct( other.
type_index, other.
ptr(), ptr() );
1961#if variant_CPP11_OR_GREATER
1971 helper_type::destroy( type_index, ptr() );
1972 type_index = variant_npos_internal();
1974 else if ( index() == other.
index() )
1976 type_index = helper_type::move_assign( other.
type_index, other.
ptr(), ptr() );
1980 helper_type::destroy( type_index, ptr() );
1981 type_index = variant_npos_internal();
1982 type_index = helper_type::move_construct( other.
type_index, other.
ptr(), ptr() );
1987 template< std::
size_t K,
class T >
1988 variant & assign_value( T && value )
1992 *as<T>() = std::forward<T>( value );
1996 helper_type::destroy( type_index, ptr() );
1997 type_index = variant_npos_internal();
1998 new( ptr() ) T( std::forward<T>( value ) );
2006 template< std::
size_t K,
class T >
2015 helper_type::destroy( type_index, ptr() );
2016 type_index = variant_npos_internal();
2017 new( ptr() ) T( value );
2028 case 0: swap( this->get<0>(), other.
get<0>() );
break;
2029 case 1: swap( this->get<1>(), other.
get<1>() );
break;
2030 case 2: swap( this->get<2>(), other.
get<2>() );
break;
2031 case 3: swap( this->get<3>(), other.
get<3>() );
break;
2032 case 4: swap( this->get<4>(), other.
get<4>() );
break;
2033 case 5: swap( this->get<5>(), other.
get<5>() );
break;
2034 case 6: swap( this->get<6>(), other.
get<6>() );
break;
2035 case 7: swap( this->get<7>(), other.
get<7>() );
break;
2036 case 8: swap( this->get<8>(), other.
get<8>() );
break;
2037 case 9: swap( this->get<9>(), other.
get<9>() );
break;
2038 case 10: swap( this->get<10>(), other.
get<10>() );
break;
2039 case 11: swap( this->get<11>(), other.
get<11>() );
break;
2040 case 12: swap( this->get<12>(), other.
get<12>() );
break;
2041 case 13: swap( this->get<13>(), other.
get<13>() );
break;
2042 case 14: swap( this->get<14>(), other.
get<14>() );
break;
2043 case 15: swap( this->get<15>(), other.
get<15>() );
break;
2051#if variant_CPP11_OR_GREATER
2053 enum { data_align = detail::typelist_max_alignof< variant_types >::value };
2055 using aligned_storage_t =
typename std::aligned_storage< data_size, data_align >::type;
2056 aligned_storage_t data;
2058#elif variant_CONFIG_MAX_ALIGN_HACK
2060 typedef union {
unsigned char data[ data_size ]; } aligned_storage_t;
2062 detail::max_align_t hack;
2063 aligned_storage_t data;
2070 typedef union { align_as_type data[ 1 + ( data_size - 1 ) /
sizeof(align_as_type) ]; }
aligned_storage_t;