10 #ifndef NONSTD_VARIANT_LITE_HPP
11 #define NONSTD_VARIANT_LITE_HPP
13 #define variant_lite_MAJOR 1
14 #define variant_lite_MINOR 1
15 #define variant_lite_PATCH 0
17 #define variant_lite_VERSION variant_STRINGIFY(variant_lite_MAJOR) "." variant_STRINGIFY(variant_lite_MINOR) "." variant_STRINGIFY(variant_lite_PATCH)
19 #define variant_STRINGIFY( x ) variant_STRINGIFY_( x )
20 #define variant_STRINGIFY_( x ) #x
24 #define variant_VARIANT_DEFAULT 0
25 #define variant_VARIANT_NONSTD 1
26 #define variant_VARIANT_STD 2
28 #if !defined( variant_CONFIG_SELECT_VARIANT )
29 # define variant_CONFIG_SELECT_VARIANT ( variant_HAVE_STD_VARIANT ? variant_VARIANT_STD : variant_VARIANT_NONSTD )
32 #ifndef variant_CONFIG_OMIT_VARIANT_SIZE_V_MACRO
33 # define variant_CONFIG_OMIT_VARIANT_SIZE_V_MACRO 0
36 #ifndef variant_CONFIG_OMIT_VARIANT_ALTERNATIVE_T_MACRO
37 # define variant_CONFIG_OMIT_VARIANT_ALTERNATIVE_T_MACRO 0
42 #ifndef variant_CONFIG_NO_EXCEPTIONS
43 # if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)
44 # define variant_CONFIG_NO_EXCEPTIONS 0
46 # define variant_CONFIG_NO_EXCEPTIONS 1
53 #ifndef variant_CPLUSPLUS
54 # if defined(_MSVC_LANG ) && !defined(__clang__)
55 # define variant_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG )
57 # define variant_CPLUSPLUS __cplusplus
61 #define variant_CPP98_OR_GREATER ( variant_CPLUSPLUS >= 199711L )
62 #define variant_CPP11_OR_GREATER ( variant_CPLUSPLUS >= 201103L )
63 #define variant_CPP11_OR_GREATER_ ( variant_CPLUSPLUS >= 201103L )
64 #define variant_CPP14_OR_GREATER ( variant_CPLUSPLUS >= 201402L )
65 #define variant_CPP17_OR_GREATER ( variant_CPLUSPLUS >= 201703L )
66 #define variant_CPP20_OR_GREATER ( variant_CPLUSPLUS >= 202000L )
70 #if variant_CPP17_OR_GREATER && defined(__has_include )
71 # if __has_include( <variant> )
72 # define variant_HAVE_STD_VARIANT 1
74 # define variant_HAVE_STD_VARIANT 0
77 # define variant_HAVE_STD_VARIANT 0
80 #define variant_USES_STD_VARIANT ( (variant_CONFIG_SELECT_VARIANT == variant_VARIANT_STD) || ((variant_CONFIG_SELECT_VARIANT == variant_VARIANT_DEFAULT) && variant_HAVE_STD_VARIANT) )
86 #ifndef nonstd_lite_HAVE_IN_PLACE_TYPES
87 #define nonstd_lite_HAVE_IN_PLACE_TYPES 1
91 #if variant_CPP17_OR_GREATER
100 using std::in_place_t;
101 using std::in_place_type_t;
102 using std::in_place_index_t;
104 #define nonstd_lite_in_place_t( T) std::in_place_t
105 #define nonstd_lite_in_place_type_t( T) std::in_place_type_t<T>
106 #define nonstd_lite_in_place_index_t(K) std::in_place_index_t<K>
108 #define nonstd_lite_in_place( T) std::in_place_t{}
109 #define nonstd_lite_in_place_type( T) std::in_place_type_t<T>{}
110 #define nonstd_lite_in_place_index(K) std::in_place_index_t<K>{}
114 #else // variant_CPP17_OR_GREATER
122 struct in_place_type_tag {};
124 template< std::
size_t K >
125 struct in_place_index_tag {};
129 struct in_place_t {};
132 inline in_place_t
in_place( detail::in_place_type_tag<T> = detail::in_place_type_tag<T>() )
137 template< std::
size_t K >
138 inline in_place_t
in_place( detail::in_place_index_tag<K> = detail::in_place_index_tag<K>() )
144 inline in_place_t
in_place_type( detail::in_place_type_tag<T> = detail::in_place_type_tag<T>() )
149 template< std::
size_t K >
150 inline in_place_t
in_place_index( detail::in_place_index_tag<K> = detail::in_place_index_tag<K>() )
157 #define nonstd_lite_in_place_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag<T> )
158 #define nonstd_lite_in_place_type_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag<T> )
159 #define nonstd_lite_in_place_index_t(K) nonstd::in_place_t(&)( nonstd::detail::in_place_index_tag<K> )
161 #define nonstd_lite_in_place( T) nonstd::in_place_type<T>
162 #define nonstd_lite_in_place_type( T) nonstd::in_place_type<T>
163 #define nonstd_lite_in_place_index(K) nonstd::in_place_index<K>
167 #endif // variant_CPP17_OR_GREATER
168 #endif // nonstd_lite_HAVE_IN_PLACE_TYPES
174 #if variant_USES_STD_VARIANT
176 #include <functional>
179 #if ! variant_CONFIG_OMIT_VARIANT_SIZE_V_MACRO
180 # define variant_size_V(T) nonstd::variant_size<T>::value
183 #if ! variant_CONFIG_OMIT_VARIANT_ALTERNATIVE_T_MACRO
184 # define variant_alternative_T(K,T) typename nonstd::variant_alternative<K,T >::type
190 using std::monostate;
191 using std::bad_variant_access;
192 using std::variant_size;
193 using std::variant_size_v;
194 using std::variant_alternative;
195 using std::variant_alternative_t;
202 using std::operator==;
203 using std::operator!=;
204 using std::operator<;
205 using std::operator<=;
206 using std::operator>;
207 using std::operator>=;
213 #else // variant_USES_STD_VARIANT
220 #if variant_CONFIG_NO_EXCEPTIONS
223 # include <stdexcept>
228 #define variant_CONFIG_MAX_TYPE_COUNT 16
229 #define variant_CONFIG_MAX_VISITOR_ARG_COUNT 5
233 #ifndef variant_CONFIG_MAX_ALIGN_HACK
234 # define variant_CONFIG_MAX_ALIGN_HACK 0
237 #ifndef variant_CONFIG_ALIGN_AS
241 #ifndef variant_CONFIG_ALIGN_AS_FALLBACK
242 # define variant_CONFIG_ALIGN_AS_FALLBACK double
246 #define variant_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) )
261 #if defined(_MSC_VER ) && !defined(__clang__)
262 # define variant_COMPILER_MSVC_VER (_MSC_VER )
263 # define variant_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) )
265 # define variant_COMPILER_MSVC_VER 0
266 # define variant_COMPILER_MSVC_VERSION 0
269 #define variant_COMPILER_VERSION( major, minor, patch ) ( 10 * ( 10 * (major) + (minor) ) + (patch) )
271 #if defined(__clang__)
272 # define variant_COMPILER_CLANG_VERSION variant_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__)
274 # define variant_COMPILER_CLANG_VERSION 0
277 #if defined(__GNUC__) && !defined(__clang__)
278 # define variant_COMPILER_GNUC_VERSION variant_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
280 # define variant_COMPILER_GNUC_VERSION 0
283 #if variant_BETWEEN( variant_COMPILER_MSVC_VER, 1300, 1900 )
284 # pragma warning( push )
285 # pragma warning( disable: 4345 ) // initialization behavior changed
290 #define variant_HAVE( feature ) ( variant_HAVE_##feature )
293 # define variant_HAS_CPP0X _HAS_CPP0X
295 # define variant_HAS_CPP0X 0
300 #if variant_COMPILER_MSVC_VER >= 1900
301 # undef variant_CPP11_OR_GREATER
302 # define variant_CPP11_OR_GREATER 1
305 #define variant_CPP11_90 (variant_CPP11_OR_GREATER_ || variant_COMPILER_MSVC_VER >= 1500)
306 #define variant_CPP11_100 (variant_CPP11_OR_GREATER_ || variant_COMPILER_MSVC_VER >= 1600)
307 #define variant_CPP11_110 (variant_CPP11_OR_GREATER_ || variant_COMPILER_MSVC_VER >= 1700)
308 #define variant_CPP11_120 (variant_CPP11_OR_GREATER_ || variant_COMPILER_MSVC_VER >= 1800)
309 #define variant_CPP11_140 (variant_CPP11_OR_GREATER_ || variant_COMPILER_MSVC_VER >= 1900)
310 #define variant_CPP11_141 (variant_CPP11_OR_GREATER_ || variant_COMPILER_MSVC_VER >= 1910)
312 #define variant_CPP14_000 (variant_CPP14_OR_GREATER)
313 #define variant_CPP17_000 (variant_CPP17_OR_GREATER)
317 #define variant_HAVE_CONSTEXPR_11 variant_CPP11_140
318 #define variant_HAVE_INITIALIZER_LIST variant_CPP11_120
319 #define variant_HAVE_NOEXCEPT variant_CPP11_140
320 #define variant_HAVE_NULLPTR variant_CPP11_100
321 #define variant_HAVE_OVERRIDE variant_CPP11_140
325 #define variant_HAVE_CONSTEXPR_14 variant_CPP14_000
333 #define variant_HAVE_CONDITIONAL variant_CPP11_120
334 #define variant_HAVE_REMOVE_CV variant_CPP11_120
335 #define variant_HAVE_STD_ADD_POINTER variant_CPP11_90
336 #define variant_HAVE_TYPE_TRAITS variant_CPP11_90
338 #define variant_HAVE_TR1_TYPE_TRAITS (!! variant_COMPILER_GNUC_VERSION )
339 #define variant_HAVE_TR1_ADD_POINTER (!! variant_COMPILER_GNUC_VERSION )
343 #if variant_HAVE_CONSTEXPR_11
344 # define variant_constexpr constexpr
346 # define variant_constexpr
349 #if variant_HAVE_CONSTEXPR_14
350 # define variant_constexpr14 constexpr
352 # define variant_constexpr14
355 #if variant_HAVE_NOEXCEPT
356 # define variant_noexcept noexcept
358 # define variant_noexcept
361 #if variant_HAVE_NULLPTR
362 # define variant_nullptr nullptr
364 # define variant_nullptr NULL
367 #if variant_HAVE_OVERRIDE
368 # define variant_override override
370 # define variant_override
375 #if variant_CPP11_OR_GREATER
376 # include <functional>
379 #if variant_HAVE_INITIALIZER_LIST
380 # include <initializer_list>
383 #if variant_HAVE_TYPE_TRAITS
384 # include <type_traits>
385 #elif variant_HAVE_TR1_TYPE_TRAITS
386 # include <tr1/type_traits>
391 #if variant_CPP11_OR_GREATER
393 #define variant_REQUIRES_0(...) \
394 template< bool B = (__VA_ARGS__), typename std::enable_if<B, int>::type = 0 >
396 #define variant_REQUIRES_T(...) \
397 , typename = typename std::enable_if< (__VA_ARGS__), nonstd::variants::detail::enabler >::type
399 #define variant_REQUIRES_R(R, ...) \
400 typename std::enable_if< (__VA_ARGS__), R>::type
402 #define variant_REQUIRES_A(...) \
403 , typename std::enable_if< (__VA_ARGS__), void*>::type = nullptr
417 #if variant_HAVE_STD_ADD_POINTER
419 using std::add_pointer;
421 #elif variant_HAVE_TR1_ADD_POINTER
423 using std::tr1::add_pointer;
435 #endif // variant_HAVE_STD_ADD_POINTER
437 #if variant_HAVE_REMOVE_CV
439 using std::remove_cv;
455 #endif // variant_HAVE_REMOVE_CV
457 #if variant_HAVE_CONDITIONAL
459 using std::conditional;
463 template<
bool Cond,
class Then,
class Else >
466 template<
class Then,
class Else >
469 template<
class Then,
class Else >
472 #endif // variant_HAVE_CONDITIONAL
480 #if variant_CPP17_OR_GREATER
482 using std::is_swappable;
483 using std::is_nothrow_swappable;
485 #elif variant_CPP11_OR_GREATER
493 template< typename T, typename = decltype( swap( std::declval<T&>(), std::declval<T&>() ) ) >
494 static std::true_type test(
int );
497 static std::false_type test(...);
500 struct is_nothrow_swappable
504 template<
typename T >
505 static constexpr
bool test()
507 return noexcept(
swap( std::declval<T&>(), std::declval<T&>() ) );
510 template<
typename T >
511 static auto test(
int ) -> std::integral_constant<bool, test<T>()>{}
514 static std::false_type test(...);
521 template<
typename T >
522 struct is_swappable : decltype( detail::is_swappable::test<T>(0) ){};
524 template<
typename T >
525 struct is_nothrow_swappable : decltype( detail::is_nothrow_swappable::test<T>(0) ){};
527 #endif // variant_CPP17_OR_GREATER
541 #define variant_TL1( T1 ) detail::typelist< T1, detail::nulltype >
542 #define variant_TL2( T1, T2) detail::typelist< T1, variant_TL1( T2) >
543 #define variant_TL3( T1, T2, T3) detail::typelist< T1, variant_TL2( T2, T3) >
544 #define variant_TL4( T1, T2, T3, T4) detail::typelist< T1, variant_TL3( T2, T3, T4) >
545 #define variant_TL5( T1, T2, T3, T4, T5) detail::typelist< T1, variant_TL4( T2, T3, T4, T5) >
546 #define variant_TL6( T1, T2, T3, T4, T5, T6) detail::typelist< T1, variant_TL5( T2, T3, T4, T5, T6) >
547 #define variant_TL7( T1, T2, T3, T4, T5, T6, T7) detail::typelist< T1, variant_TL6( T2, T3, T4, T5, T6, T7) >
548 #define variant_TL8( T1, T2, T3, T4, T5, T6, T7, T8) detail::typelist< T1, variant_TL7( T2, T3, T4, T5, T6, T7, T8) >
549 #define variant_TL9( T1, T2, T3, T4, T5, T6, T7, T8, T9) detail::typelist< T1, variant_TL8( T2, T3, T4, T5, T6, T7, T8, T9) >
550 #define variant_TL10( T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) detail::typelist< T1, variant_TL9( T2, T3, T4, T5, T6, T7, T8, T9, T10) >
551 #define variant_TL11( T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) detail::typelist< T1, variant_TL10( T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) >
552 #define variant_TL12( T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) detail::typelist< T1, variant_TL11( T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) >
553 #define variant_TL13( T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) detail::typelist< T1, variant_TL12( T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) >
554 #define variant_TL14( T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) detail::typelist< T1, variant_TL13( T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) >
555 #define variant_TL15( T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) detail::typelist< T1, variant_TL14( T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) >
556 #define variant_TL16( T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) detail::typelist< T1, variant_TL15( T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) >
583 inline bool operator< ( T
const & )
const {
return false; }
593 struct S0{};
typedef TX<S0>
T0;
594 struct S1{};
typedef TX<S1>
T1;
595 struct S2{};
typedef TX<S2>
T2;
596 struct S3{};
typedef TX<S3>
T3;
597 struct S4{};
typedef TX<S4>
T4;
598 struct S5{};
typedef TX<S5>
T5;
599 struct S6{};
typedef TX<S6>
T6;
600 struct S7{};
typedef TX<S7>
T7;
601 struct S8{};
typedef TX<S8>
T8;
602 struct S9{};
typedef TX<S9>
T9;
613 template<
class Head,
class Tail >
622 template<
class List >
628 enum V { value = 0 } ;
632 template<
class Head,
class Tail >
641 enum V { value = (
sizeof( Head ) > tail_value) ?
sizeof( Head ) : std::size_t( tail_value ) } ;
646 #if variant_CPP11_OR_GREATER
650 template<
class List >
651 struct typelist_max_alignof;
654 struct typelist_max_alignof<
nulltype >
656 enum V { value = 0 } ;
659 template<
class Head,
class Tail >
660 struct typelist_max_alignof< typelist<Head, Tail> >
663 enum TV { tail_value = size_t( typelist_max_alignof<Tail>::value ) };
666 enum V { value = (
alignof( Head ) > tail_value) ?
alignof( Head ) : std::size_t( tail_value ) };
673 template<
class List >
699 template<
class Head,
class Tail >
707 template<
class List,
class T >
713 enum V { value = -1 };
716 template<
class Tail,
class T >
719 enum V { value = 0 };
722 template<
class Head,
class Tail,
class T >
729 enum V { value = nextVal == -1 ? -1 : 1 + nextVal } ;
734 template<
class List, std::
size_t i>
737 template<
class Head,
class Tail >
743 template<
class Head,
class Tail, std::
size_t i >
749 #if variant_CONFIG_MAX_ALIGN_HACK
753 #define variant_UNIQUE( name ) variant_UNIQUE2( name, __LINE__ )
754 #define variant_UNIQUE2( name, line ) variant_UNIQUE3( name, line )
755 #define variant_UNIQUE3( name, line ) name ## line
757 #define variant_ALIGN_TYPE( type ) \
758 type variant_UNIQUE( _t ); struct_t< type > variant_UNIQUE( _st )
781 #ifdef HAVE_LONG_LONG
787 Unknown ( * variant_UNIQUE(_) )( Unknown );
788 Unknown * Unknown::* variant_UNIQUE(_);
789 Unknown ( Unknown::* variant_UNIQUE(_) )( Unknown );
791 struct_t< Unknown ( * )( Unknown) > variant_UNIQUE(_);
792 struct_t< Unknown * Unknown::* > variant_UNIQUE(_);
793 struct_t< Unknown ( Unknown::* )(Unknown) > variant_UNIQUE(_);
796 #undef variant_UNIQUE
797 #undef variant_UNIQUE2
798 #undef variant_UNIQUE3
800 #undef variant_ALIGN_TYPE
802 #elif defined( variant_CONFIG_ALIGN_AS ) // variant_CONFIG_MAX_ALIGN_HACK
806 #define variant_ALIGN_AS( unused ) \
807 variant_CONFIG_ALIGN_AS
809 #else // variant_CONFIG_MAX_ALIGN_HACK
813 #define variant_ALIGN_AS( to_align ) \
814 typename detail::type_of_size< detail::alignment_types, detail::alignment_of< to_align >::value >::type
816 template<
typename T >
819 template<
typename T >
827 template<
size_t A,
size_t S >
830 enum V { value = A < S ? A : S };
833 template<
typename T >
840 template<
typename List,
size_t N >
844 N ==
sizeof(
typename List::head ),
855 template<
typename T>
858 #define variant_ALIGN_TYPE( type ) \
859 typelist< type , typelist< struct_t< type >
885 > > > > > > > > > > > > > >
886 > > > > > > > > > > > > > >
890 #undef variant_ALIGN_TYPE
892 #endif // variant_CONFIG_MAX_ALIGN_HACK
894 #if variant_CPP11_OR_GREATER
896 template<
typename T>
897 inline std::size_t hash( T
const & v )
899 return std::hash<T>()( v );
902 inline std::size_t hash(
T0 const & ) {
return 0; }
903 inline std::size_t hash(
T1 const & ) {
return 0; }
904 inline std::size_t hash(
T2 const & ) {
return 0; }
905 inline std::size_t hash(
T3 const & ) {
return 0; }
906 inline std::size_t hash(
T4 const & ) {
return 0; }
907 inline std::size_t hash(
T5 const & ) {
return 0; }
908 inline std::size_t hash(
T6 const & ) {
return 0; }
909 inline std::size_t hash(
T7 const & ) {
return 0; }
910 inline std::size_t hash(
T8 const & ) {
return 0; }
911 inline std::size_t hash(
T9 const & ) {
return 0; }
912 inline std::size_t hash(
T10 const & ) {
return 0; }
913 inline std::size_t hash(
T11 const & ) {
return 0; }
914 inline std::size_t hash(
T12 const & ) {
return 0; }
915 inline std::size_t hash(
T13 const & ) {
return 0; }
916 inline std::size_t hash(
T14 const & ) {
return 0; }
917 inline std::size_t hash(
T15 const & ) {
return 0; }
920 #endif // variant_CPP11_OR_GREATER
926 template<
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
930 typedef variant_TL16(
T0,
T1,
T2,
T3,
T4,
T5,
T6,
T7,
T8,
T9,
T10,
T11,
T12,
T13,
T14,
T15 ) variant_types;
933 static U *
as(
void * data )
935 return reinterpret_cast<U*
>( data );
939 static U
const *
as(
void const * data )
941 return reinterpret_cast<const U*
>( data );
953 case 0: as<T0>( data )->~T0();
break;
954 case 1: as<T1>( data )->~T1();
break;
955 case 2: as<T2>( data )->~T2();
break;
956 case 3: as<T3>( data )->~T3();
break;
957 case 4: as<T4>( data )->~T4();
break;
958 case 5: as<T5>( data )->~T5();
break;
959 case 6: as<T6>( data )->~T6();
break;
960 case 7: as<T7>( data )->~T7();
break;
961 case 8: as<T8>( data )->~T8();
break;
962 case 9: as<T9>( data )->~T9();
break;
963 case 10: as<T10>( data )->~T10();
break;
964 case 11: as<T11>( data )->~T11();
break;
965 case 12: as<T12>( data )->~T12();
break;
966 case 13: as<T13>( data )->~T13();
break;
967 case 14: as<T14>( data )->~T14();
break;
968 case 15: as<T15>( data )->~T15();
break;
973 #if variant_CPP11_OR_GREATER
974 template<
class T,
class... Args >
975 static type_index_t construct_t(
void * data, Args&&... args )
977 new( data ) T( std::forward<Args>(args)... );
982 template< std::size_t K,
class... Args >
983 static type_index_t construct_i(
void * data, Args&&... args )
987 construct_t< type >( data, std::forward<Args>(args)... );
994 switch ( from_index )
996 case 0:
new( to_value )
T0(
std::move( *as<T0>( from_value ) ) );
break;
997 case 1:
new( to_value )
T1(
std::move( *as<T1>( from_value ) ) );
break;
998 case 2:
new( to_value )
T2(
std::move( *as<T2>( from_value ) ) );
break;
999 case 3:
new( to_value )
T3(
std::move( *as<T3>( from_value ) ) );
break;
1000 case 4:
new( to_value )
T4(
std::move( *as<T4>( from_value ) ) );
break;
1001 case 5:
new( to_value )
T5(
std::move( *as<T5>( from_value ) ) );
break;
1002 case 6:
new( to_value )
T6(
std::move( *as<T6>( from_value ) ) );
break;
1003 case 7:
new( to_value )
T7(
std::move( *as<T7>( from_value ) ) );
break;
1004 case 8:
new( to_value )
T8(
std::move( *as<T8>( from_value ) ) );
break;
1005 case 9:
new( to_value )
T9(
std::move( *as<T9>( from_value ) ) );
break;
1006 case 10:
new( to_value )
T10(
std::move( *as<T10>( from_value ) ) );
break;
1007 case 11:
new( to_value )
T11(
std::move( *as<T11>( from_value ) ) );
break;
1008 case 12:
new( to_value )
T12(
std::move( *as<T12>( from_value ) ) );
break;
1009 case 13:
new( to_value )
T13(
std::move( *as<T13>( from_value ) ) );
break;
1010 case 14:
new( to_value )
T14(
std::move( *as<T14>( from_value ) ) );
break;
1011 case 15:
new( to_value )
T15(
std::move( *as<T15>( from_value ) ) );
break;
1019 switch ( from_index )
1021 case 0: *as<T0>( to_value ) =
std::move( *as<T0>( from_value ) );
break;
1022 case 1: *as<T1>( to_value ) =
std::move( *as<T1>( from_value ) );
break;
1023 case 2: *as<T2>( to_value ) =
std::move( *as<T2>( from_value ) );
break;
1024 case 3: *as<T3>( to_value ) =
std::move( *as<T3>( from_value ) );
break;
1025 case 4: *as<T4>( to_value ) =
std::move( *as<T4>( from_value ) );
break;
1026 case 5: *as<T5>( to_value ) =
std::move( *as<T5>( from_value ) );
break;
1027 case 6: *as<T6>( to_value ) =
std::move( *as<T6>( from_value ) );
break;
1028 case 7: *as<T7>( to_value ) =
std::move( *as<T7>( from_value ) );
break;
1029 case 8: *as<T8>( to_value ) =
std::move( *as<T8>( from_value ) );
break;
1030 case 9: *as<T9>( to_value ) =
std::move( *as<T9>( from_value ) );
break;
1031 case 10: *as<T10>( to_value ) =
std::move( *as<T10>( from_value ) );
break;
1032 case 11: *as<T11>( to_value ) =
std::move( *as<T11>( from_value ) );
break;
1033 case 12: *as<T12>( to_value ) =
std::move( *as<T12>( from_value ) );
break;
1034 case 13: *as<T13>( to_value ) =
std::move( *as<T13>( from_value ) );
break;
1035 case 14: *as<T14>( to_value ) =
std::move( *as<T14>( from_value ) );
break;
1036 case 15: *as<T15>( to_value ) =
std::move( *as<T15>( from_value ) );
break;
1045 switch ( from_index )
1047 case 0:
new( to_value )
T0( *as<T0>( from_value ) );
break;
1048 case 1:
new( to_value )
T1( *as<T1>( from_value ) );
break;
1049 case 2:
new( to_value )
T2( *as<T2>( from_value ) );
break;
1050 case 3:
new( to_value )
T3( *as<T3>( from_value ) );
break;
1051 case 4:
new( to_value )
T4( *as<T4>( from_value ) );
break;
1052 case 5:
new( to_value )
T5( *as<T5>( from_value ) );
break;
1053 case 6:
new( to_value )
T6( *as<T6>( from_value ) );
break;
1054 case 7:
new( to_value )
T7( *as<T7>( from_value ) );
break;
1055 case 8:
new( to_value )
T8( *as<T8>( from_value ) );
break;
1056 case 9:
new( to_value )
T9( *as<T9>( from_value ) );
break;
1057 case 10:
new( to_value )
T10( *as<T10>( from_value ) );
break;
1058 case 11:
new( to_value )
T11( *as<T11>( from_value ) );
break;
1059 case 12:
new( to_value )
T12( *as<T12>( from_value ) );
break;
1060 case 13:
new( to_value )
T13( *as<T13>( from_value ) );
break;
1061 case 14:
new( to_value )
T14( *as<T14>( from_value ) );
break;
1062 case 15:
new( to_value )
T15( *as<T15>( from_value ) );
break;
1070 switch ( from_index )
1072 case 0: *as<T0>( to_value ) = *as<T0>( from_value );
break;
1073 case 1: *as<T1>( to_value ) = *as<T1>( from_value );
break;
1074 case 2: *as<T2>( to_value ) = *as<T2>( from_value );
break;
1075 case 3: *as<T3>( to_value ) = *as<T3>( from_value );
break;
1076 case 4: *as<T4>( to_value ) = *as<T4>( from_value );
break;
1077 case 5: *as<T5>( to_value ) = *as<T5>( from_value );
break;
1078 case 6: *as<T6>( to_value ) = *as<T6>( from_value );
break;
1079 case 7: *as<T7>( to_value ) = *as<T7>( from_value );
break;
1080 case 8: *as<T8>( to_value ) = *as<T8>( from_value );
break;
1081 case 9: *as<T9>( to_value ) = *as<T9>( from_value );
break;
1082 case 10: *as<T10>( to_value ) = *as<T10>( from_value );
break;
1083 case 11: *as<T11>( to_value ) = *as<T11>( from_value );
break;
1084 case 12: *as<T12>( to_value ) = *as<T12>( from_value );
break;
1085 case 13: *as<T13>( to_value ) = *as<T13>( from_value );
break;
1086 case 14: *as<T14>( to_value ) = *as<T14>( from_value );
break;
1087 case 15: *as<T15>( to_value ) = *as<T15>( from_value );
break;
1100 template<
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1123 template<
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1124 struct variant_size<
variant<
T0,
T1,
T2,
T3,
T4,
T5,
T6,
T7,
T8,
T9,
T10,
T11,
T12,
T13,
T14,
T15> >
1126 enum _ { value =
detail::typelist_size<
variant_TL16(
T0,
T1,
T2,
T3,
T4,
T5,
T6,
T7,
T8,
T9,
T10,
T11,
T12,
T13,
T14,
T15) >::value };
1129 #if variant_CPP14_OR_GREATER
1134 #if ! variant_CONFIG_OMIT_VARIANT_SIZE_V_MACRO
1135 # define variant_size_V(T) nonstd::variant_size<T>::value
1140 template< std::
size_t K,
class T >
1143 template< std::
size_t K,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1144 struct variant_alternative< K,
variant<
T0,
T1,
T2,
T3,
T4,
T5,
T6,
T7,
T8,
T9,
T10,
T11,
T12,
T13,
T14,
T15> >
1146 typedef typename detail::typelist_type_at<
variant_TL16(
T0,
T1,
T2,
T3,
T4,
T5,
T6,
T7,
T8,
T9,
T10,
T11,
T12,
T13,
T14,
T15), K>
::type type;
1149 #if variant_CPP11_OR_GREATER
1150 template< std::
size_t K,
class T >
1154 #if ! variant_CONFIG_OMIT_VARIANT_ALTERNATIVE_T_MACRO
1155 # define variant_alternative_T(K,T) typename nonstd::variant_alternative<K,T >::type
1163 #if variant_CPP11_OR_GREATER
1169 #if ! variant_CONFIG_NO_EXCEPTIONS
1173 class bad_variant_access :
public std::exception
1176 #if variant_CPP11_OR_GREATER
1179 virtual const char* what()
const throw()
1182 return "bad variant access";
1186 #endif // variant_CONFIG_NO_EXCEPTIONS
1210 typedef detail::helper< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 > helper_type;
1211 typedef variant_TL16(
T0,
T1,
T2,
T3,
T4,
T5,
T6,
T7,
T8,
T9,
T10,
T11,
T12,
T13,
T14,
T15 ) variant_types;
1236 #if variant_CPP11_OR_GREATER
1257 : type_index( other.type_index )
1262 #if variant_CPP11_OR_GREATER
1265 std::is_nothrow_move_constructible<T0>::value &&
1266 std::is_nothrow_move_constructible<T1>::value &&
1267 std::is_nothrow_move_constructible<T2>::value &&
1268 std::is_nothrow_move_constructible<T3>::value &&
1269 std::is_nothrow_move_constructible<T4>::value &&
1270 std::is_nothrow_move_constructible<T5>::value &&
1271 std::is_nothrow_move_constructible<T6>::value &&
1272 std::is_nothrow_move_constructible<T7>::value &&
1273 std::is_nothrow_move_constructible<T8>::value &&
1274 std::is_nothrow_move_constructible<T9>::value &&
1275 std::is_nothrow_move_constructible<T10>::value &&
1276 std::is_nothrow_move_constructible<T11>::value &&
1277 std::is_nothrow_move_constructible<T12>::value &&
1278 std::is_nothrow_move_constructible<T13>::value &&
1279 std::is_nothrow_move_constructible<T14>::value &&
1280 std::is_nothrow_move_constructible<T15>::value)
1281 : type_index( other.type_index )
1283 (void) helper_type::move_construct( other.type_index, other.ptr(), ptr() );
1286 template< std::
size_t K >
1287 using type_at_t =
typename detail::typelist_type_at< variant_types, K >::type;
1289 template<
class T,
class... Args
1290 variant_REQUIRES_T( std::is_constructible< T, Args...>::value )
1294 type_index = variant_npos_internal();
1295 type_index = helper_type::template construct_t<T>( ptr(), std::forward<Args>(args)... );
1298 template<
class T,
class U,
class... Args
1299 variant_REQUIRES_T( std::is_constructible< T, std::initializer_list<U>&, Args...>::value )
1303 type_index = variant_npos_internal();
1304 type_index = helper_type::template construct_t<T>( ptr(), il, std::forward<Args>(args)... );
1307 template< std::size_t K,
class... Args
1308 variant_REQUIRES_T( std::is_constructible< type_at_t<K>, Args...>::value )
1312 type_index = variant_npos_internal();
1313 type_index = helper_type::template construct_i<K>( ptr(), std::forward<Args>(args)... );
1316 template<
size_t K,
class U,
class... Args
1317 variant_REQUIRES_T( std::is_constructible< type_at_t<K>, std::initializer_list<U>&, Args...>::value )
1321 type_index = variant_npos_internal();
1322 type_index = helper_type::template construct_i<K>( ptr(), il, std::forward<Args>(args)... );
1325 #endif // variant_CPP11_OR_GREATER
1341 return copy_assign( other );
1344 #if variant_CPP11_OR_GREATER
1347 std::is_nothrow_move_assignable<T0>::value &&
1348 std::is_nothrow_move_assignable<T1>::value &&
1349 std::is_nothrow_move_assignable<T2>::value &&
1350 std::is_nothrow_move_assignable<T3>::value &&
1351 std::is_nothrow_move_assignable<T4>::value &&
1352 std::is_nothrow_move_assignable<T5>::value &&
1353 std::is_nothrow_move_assignable<T6>::value &&
1354 std::is_nothrow_move_assignable<T7>::value &&
1355 std::is_nothrow_move_assignable<T8>::value &&
1356 std::is_nothrow_move_assignable<T9>::value &&
1357 std::is_nothrow_move_assignable<T10>::value &&
1358 std::is_nothrow_move_assignable<T11>::value &&
1359 std::is_nothrow_move_assignable<T12>::value &&
1360 std::is_nothrow_move_assignable<T13>::value &&
1361 std::is_nothrow_move_assignable<T14>::value &&
1362 std::is_nothrow_move_assignable<T15>::value)
1364 return move_assign(
std::move( other ) );
1407 return variant_npos_internal() == type_index ?
variant_npos :
static_cast<std::size_t
>( type_index );
1412 #if variant_CPP11_OR_GREATER
1413 template<
class T,
class... Args
1414 variant_REQUIRES_T( std::is_constructible< T, Args...>::value )
1416 T& emplace( Args&&... args )
1419 type_index = variant_npos_internal();
1420 type_index = helper_type::template construct_t<T>( ptr(), std::forward<Args>(args)... );
1425 template<
class T,
class U,
class... Args
1426 variant_REQUIRES_T( std::is_constructible< T, std::initializer_list<U>&, Args...>::value )
1428 T& emplace( std::initializer_list<U> il, Args&&... args )
1431 type_index = variant_npos_internal();
1432 type_index = helper_type::template construct_t<T>( ptr(), il, std::forward<Args>(args)... );
1437 template<
size_t K,
class... Args
1438 variant_REQUIRES_T( std::is_constructible< type_at_t<K>, Args...>::value )
1440 variant_alternative_t<K, variant> & emplace( Args&&... args )
1442 return this->
template emplace< type_at_t<K> >( std::forward<Args>(args)... );
1445 template<
size_t K,
class U,
class... Args
1446 variant_REQUIRES_T( std::is_constructible< type_at_t<K>, std::initializer_list<U>&, Args...>::value )
1448 variant_alternative_t<K, variant> & emplace( std::initializer_list<U> il, Args&&... args )
1450 return this->
template emplace< type_at_t<K> >( il, std::forward<Args>(args)... );
1453 #endif // variant_CPP11_OR_GREATER
1459 return type_index == variant_npos_internal();
1465 #if variant_CPP11_OR_GREATER
1467 std::is_nothrow_move_constructible<T0>::value && std17::is_nothrow_swappable<T0>::value &&
1468 std::is_nothrow_move_constructible<T1>::value && std17::is_nothrow_swappable<T1>::value &&
1469 std::is_nothrow_move_constructible<T2>::value && std17::is_nothrow_swappable<T2>::value &&
1470 std::is_nothrow_move_constructible<T3>::value && std17::is_nothrow_swappable<T3>::value &&
1471 std::is_nothrow_move_constructible<T4>::value && std17::is_nothrow_swappable<T4>::value &&
1472 std::is_nothrow_move_constructible<T5>::value && std17::is_nothrow_swappable<T5>::value &&
1473 std::is_nothrow_move_constructible<T6>::value && std17::is_nothrow_swappable<T6>::value &&
1474 std::is_nothrow_move_constructible<T7>::value && std17::is_nothrow_swappable<T7>::value &&
1475 std::is_nothrow_move_constructible<T8>::value && std17::is_nothrow_swappable<T8>::value &&
1476 std::is_nothrow_move_constructible<T9>::value && std17::is_nothrow_swappable<T9>::value &&
1477 std::is_nothrow_move_constructible<T10>::value && std17::is_nothrow_swappable<T10>::value &&
1478 std::is_nothrow_move_constructible<T11>::value && std17::is_nothrow_swappable<T11>::value &&
1479 std::is_nothrow_move_constructible<T12>::value && std17::is_nothrow_swappable<T12>::value &&
1480 std::is_nothrow_move_constructible<T13>::value && std17::is_nothrow_swappable<T13>::value &&
1481 std::is_nothrow_move_constructible<T14>::value && std17::is_nothrow_swappable<T14>::value &&
1482 std::is_nothrow_move_constructible<T15>::value && std17::is_nothrow_swappable<T15>::value
1491 else if ( type_index == other.type_index )
1493 this->swap_value( type_index, other );
1497 #if variant_CPP11_OR_GREATER
1522 const std::size_t i = index_of<T>();
1524 #if variant_CONFIG_NO_EXCEPTIONS
1525 assert( i ==
index() );
1529 throw bad_variant_access();
1538 const std::size_t i = index_of<T>();
1540 #if variant_CONFIG_NO_EXCEPTIONS
1541 assert( i ==
index() );
1545 throw bad_variant_access();
1548 return *as<const T>();
1551 template< std::
size_t K >
1555 return this->
template get< typename detail::typelist_type_at< variant_types, K >::type >();
1558 template< std::
size_t K >
1562 return this->
template get< typename detail::typelist_type_at< variant_types, K >::type >();
1581 return reinterpret_cast<U*
>( ptr() );
1585 U
const * as()
const
1587 return reinterpret_cast<U
const *
>( ptr() );
1593 return static_cast<std::size_t
>(
index );
1598 return static_cast<type_index_t
>( -1 );
1610 type_index = variant_npos_internal();
1612 else if (
index() == other.index() )
1619 type_index = variant_npos_internal();
1625 #if variant_CPP11_OR_GREATER
1636 type_index = variant_npos_internal();
1638 else if (
index() == other.index() )
1640 type_index = helper_type::move_assign( other.type_index, other.ptr(), ptr() );
1645 type_index = variant_npos_internal();
1646 type_index = helper_type::move_construct( other.type_index, other.ptr(), ptr() );
1651 template< std::
size_t K,
class T >
1652 variant & assign_value( T && value )
1656 *as<T>() = std::forward<T>( value );
1661 type_index = variant_npos_internal();
1662 new( ptr() ) T( std::forward<T>( value ) );
1668 #endif // variant_CPP11_OR_GREATER
1670 template< std::
size_t K,
class T >
1671 variant & assign_value( T
const & value )
1680 type_index = variant_npos_internal();
1681 new( ptr() ) T( value );
1692 case 0:
swap( this->get<0>(), other.get<0>() );
break;
1693 case 1:
swap( this->get<1>(), other.get<1>() );
break;
1694 case 2:
swap( this->get<2>(), other.get<2>() );
break;
1695 case 3:
swap( this->get<3>(), other.get<3>() );
break;
1696 case 4:
swap( this->get<4>(), other.get<4>() );
break;
1697 case 5:
swap( this->get<5>(), other.get<5>() );
break;
1698 case 6:
swap( this->get<6>(), other.get<6>() );
break;
1699 case 7:
swap( this->get<7>(), other.get<7>() );
break;
1700 case 8:
swap( this->get<8>(), other.get<8>() );
break;
1701 case 9:
swap( this->get<9>(), other.get<9>() );
break;
1702 case 10:
swap( this->get<10>(), other.get<10>() );
break;
1703 case 11:
swap( this->get<11>(), other.get<11>() );
break;
1704 case 12:
swap( this->get<12>(), other.get<12>() );
break;
1705 case 13:
swap( this->get<13>(), other.get<13>() );
break;
1706 case 14:
swap( this->get<14>(), other.get<14>() );
break;
1707 case 15:
swap( this->get<15>(), other.get<15>() );
break;
1713 enum { data_size = detail::typelist_max< variant_types >::value };
1715 #if variant_CPP11_OR_GREATER
1717 enum { data_align = detail::typelist_max_alignof< variant_types >::value };
1719 using aligned_storage_t =
typename std::aligned_storage< data_size, data_align >::type;
1720 aligned_storage_t data;
1722 #elif variant_CONFIG_MAX_ALIGN_HACK
1724 typedef union {
unsigned char data[ data_size ]; } aligned_storage_t;
1726 detail::max_align_t hack;
1727 aligned_storage_t data;
1730 typedef typename detail::typelist_max< variant_types >::type max_type;
1732 typedef variant_ALIGN_AS( max_type ) align_as_type;
1734 typedef union { align_as_type data[ 1 + ( data_size - 1 ) /
sizeof(align_as_type) ]; } aligned_storage_t;
1735 aligned_storage_t data;
1739 #endif // variant_CONFIG_MAX_ALIGN_HACK
1741 type_index_t type_index;
1746 template<
class T,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1747 inline bool holds_alternative(
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & v )
variant_noexcept
1749 return v.index() ==
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::template index_of<T>();
1752 template<
class R,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1753 inline R &
get(
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> & v,
nonstd_lite_in_place_type_t(R) =
nonstd_lite_in_place_type(R) )
1755 return v.template get<R>();
1758 template<
class R,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1759 inline R
const &
get(
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & v,
nonstd_lite_in_place_type_t(R) =
nonstd_lite_in_place_type(R) )
1761 return v.template get<R>();
1764 template< std::
size_t K,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1765 inline typename variant_alternative< K, variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> >::type &
1766 get(
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> & v,
nonstd_lite_in_place_index_t(K) =
nonstd_lite_in_place_index(K) )
1768 #if variant_CONFIG_NO_EXCEPTIONS
1769 assert( K == v.
index() );
1771 if ( K != v.
index() )
1773 throw bad_variant_access();
1776 return v.template get<K>();
1779 template< std::
size_t K,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1780 inline typename variant_alternative< K, variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> >::type
const &
1781 get(
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & v,
nonstd_lite_in_place_index_t(K) =
nonstd_lite_in_place_index(K) )
1783 #if variant_CONFIG_NO_EXCEPTIONS
1784 assert( K == v.
index() );
1786 if ( K != v.
index() )
1788 throw bad_variant_access();
1791 return v.template get<K>();
1794 #if variant_CPP11_OR_GREATER
1796 template<
class R,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1797 inline R &&
get(
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> && v,
nonstd_lite_in_place_type_t(R) =
nonstd_lite_in_place_type(R) )
1802 template<
class R,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1803 inline R
const &&
get( variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>
const && v,
nonstd_lite_in_place_type_t(R) =
nonstd_lite_in_place_type(R) )
1808 template< std::
size_t K,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1809 inline typename variant_alternative< K, variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> >::type &&
1810 get( variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> && v,
nonstd_lite_in_place_index_t(K) =
nonstd_lite_in_place_index(K) )
1812 #if variant_CONFIG_NO_EXCEPTIONS
1813 assert( K == v.
index() );
1815 if ( K != v.
index() )
1817 throw bad_variant_access();
1823 template< std::
size_t K,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1824 inline typename variant_alternative< K, variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> >::type
const &&
1825 get( variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>
const && v,
nonstd_lite_in_place_index_t(K) =
nonstd_lite_in_place_index(K) )
1827 #if variant_CONFIG_NO_EXCEPTIONS
1828 assert( K == v.
index() );
1830 if ( K != v.
index() )
1832 throw bad_variant_access();
1838 #endif // variant_CPP11_OR_GREATER
1840 template<
class T,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1842 get_if(
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> * pv,
nonstd_lite_in_place_type_t(T) =
nonstd_lite_in_place_type(T) )
1844 return ( pv->
index() ==
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::template index_of<T>() ) ? &get<T>( *pv ) :
variant_nullptr;
1847 template<
class T,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1849 get_if(
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const * pv,
nonstd_lite_in_place_type_t(T) =
nonstd_lite_in_place_type(T))
1851 return ( pv->
index() ==
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::template index_of<T>() ) ? &get<T>( *pv ) :
variant_nullptr;
1854 template< std::
size_t K,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1855 inline typename std11::add_pointer< typename variant_alternative<K, variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> >::type >::type
1856 get_if(
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> * pv,
nonstd_lite_in_place_index_t(K) =
nonstd_lite_in_place_index(K) )
1861 template< std::
size_t K,
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
1862 inline typename std11::add_pointer< const typename variant_alternative<K, variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> >::type >::type
1863 get_if(
variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const * pv,
nonstd_lite_in_place_index_t(K) =
nonstd_lite_in_place_index(K) )
1870 template<
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15
1871 #if variant_CPP11_OR_GREATER
1873 std::is_move_constructible<T0>::value && std17::is_swappable<T0>::value &&
1874 std::is_move_constructible<T1>::value && std17::is_swappable<T1>::value &&
1875 std::is_move_constructible<T2>::value && std17::is_swappable<T2>::value &&
1876 std::is_move_constructible<T3>::value && std17::is_swappable<T3>::value &&
1877 std::is_move_constructible<T4>::value && std17::is_swappable<T4>::value &&
1878 std::is_move_constructible<T5>::value && std17::is_swappable<T5>::value &&
1879 std::is_move_constructible<T6>::value && std17::is_swappable<T6>::value &&
1880 std::is_move_constructible<T7>::value && std17::is_swappable<T7>::value &&
1881 std::is_move_constructible<T8>::value && std17::is_swappable<T8>::value &&
1882 std::is_move_constructible<T9>::value && std17::is_swappable<T9>::value &&
1883 std::is_move_constructible<T10>::value && std17::is_swappable<T10>::value &&
1884 std::is_move_constructible<T11>::value && std17::is_swappable<T11>::value &&
1885 std::is_move_constructible<T12>::value && std17::is_swappable<T12>::value &&
1886 std::is_move_constructible<T13>::value && std17::is_swappable<T13>::value &&
1887 std::is_move_constructible<T14>::value && std17::is_swappable<T14>::value &&
1888 std::is_move_constructible<T15>::value && std17::is_swappable<T15>::value
1893 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> & a,
1894 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> & b )
1895 #if variant_CPP11_OR_GREATER
1896 noexcept( noexcept( a.
swap( b ) ) )
1909 template<
typename R,
typename VT >
1912 template<
typename Visitor,
typename T >
1913 static R
apply(Visitor
const& v, T
const& arg)
1919 template<
typename R,
typename VT >
1922 template<
typename Visitor,
typename T >
1929 template<
typename R>
1932 template<
typename R,
typename Visitor,
typename V1 >
1935 #if variant_CPP11_OR_GREATER
1936 template<
size_t NumVars,
typename R,
typename Visitor,
typename ... T >
1938 template<
size_t NumVars,
typename R,
typename Visitor,
typename T1,
typename T2 = S0,
typename T3 = S0,
typename T4 = S0,
typename T5 = S0 >
1942 template<
typename R,
typename Visitor,
typename T2 >
1955 template<
typename T>
1958 return visitor(val1, val2);
1962 template<
typename R,
typename Visitor,
typename T2,
typename T3 >
1977 template<
typename T>
1980 return visitor(val1, val2, val3);
1984 template<
typename R,
typename Visitor,
typename T2,
typename T3,
typename T4 >
2001 template<
typename T>
2004 return visitor(val1, val2, val3, val4);
2008 template<
typename R,
typename Visitor,
typename T2,
typename T3,
typename T4,
typename T5 >
2027 template<
typename T>
2030 return visitor(val1, val2, val3, val4, val5);
2036 template<
typename R,
typename Visitor,
typename V2>
2037 struct VisitorUnwrapper
2049 template<
typename T1 >
2056 template<
typename T1,
typename T2 >
2063 template<
typename T1,
typename T2,
typename T3 >
2070 template<
typename T1,
typename T2,
typename T3,
typename T4 >
2077 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5 >
2087 template<
typename R>
2088 struct VisitorApplicator
2090 template<
typename Visitor,
typename V1>
2091 static R
apply(
const Visitor& v,
const V1& arg)
2093 switch( arg.index() )
2095 case 0:
return apply_visitor<0>(v, arg);
2096 case 1:
return apply_visitor<1>(v, arg);
2097 case 2:
return apply_visitor<2>(v, arg);
2098 case 3:
return apply_visitor<3>(v, arg);
2099 case 4:
return apply_visitor<4>(v, arg);
2100 case 5:
return apply_visitor<5>(v, arg);
2101 case 6:
return apply_visitor<6>(v, arg);
2102 case 7:
return apply_visitor<7>(v, arg);
2103 case 8:
return apply_visitor<8>(v, arg);
2104 case 9:
return apply_visitor<9>(v, arg);
2105 case 10:
return apply_visitor<10>(v, arg);
2106 case 11:
return apply_visitor<11>(v, arg);
2107 case 12:
return apply_visitor<12>(v, arg);
2108 case 13:
return apply_visitor<13>(v, arg);
2109 case 14:
return apply_visitor<14>(v, arg);
2110 case 15:
return apply_visitor<15>(v, arg);
2112 default:
return R();
2116 template<
size_t Idx,
typename Visitor,
typename V1>
2120 #if variant_CPP11_OR_GREATER
2128 #if variant_CPP11_OR_GREATER
2129 template<
typename Visitor,
typename V1,
typename V2,
typename ... V>
2130 static R
apply(
const Visitor& v,
const V1& arg1,
const V2& arg2,
const V ... args)
2133 Unwrapper unwrapper(v, arg1);
2134 return apply(unwrapper, arg2, args ...);
2138 template<
typename Visitor,
typename V1,
typename V2 >
2139 static R
apply(
const Visitor& v, V1
const& arg1, V2
const& arg2)
2142 Unwrapper unwrapper(v, arg1);
2143 return apply(unwrapper, arg2);
2146 template<
typename Visitor,
typename V1,
typename V2,
typename V3 >
2147 static R
apply(
const Visitor& v, V1
const& arg1, V2
const& arg2, V3
const& arg3)
2150 Unwrapper unwrapper(v, arg1);
2151 return apply(unwrapper, arg2, arg3);
2154 template<
typename Visitor,
typename V1,
typename V2,
typename V3,
typename V4 >
2155 static R
apply(
const Visitor& v, V1
const& arg1, V2
const& arg2, V3
const& arg3, V4
const& arg4)
2158 Unwrapper unwrapper(v, arg1);
2159 return apply(unwrapper, arg2, arg3, arg4);
2162 template<
typename Visitor,
typename V1,
typename V2,
typename V3,
typename V4,
typename V5 >
2163 static R
apply(
const Visitor& v, V1
const& arg1, V2
const& arg2, V3
const& arg3, V4
const& arg4, V5
const& arg5)
2166 Unwrapper unwrapper(v, arg1);
2167 return apply(unwrapper, arg2, arg3, arg4, arg5);
2173 #if variant_CPP11_OR_GREATER
2174 template<
size_t NumVars,
typename Visitor,
typename ... V >
2177 typedef decltype(std::declval<Visitor>()(get<0>(
static_cast<const V&
>(std::declval<V>()))...)) result_type;
2178 typedef VisitorApplicator<result_type> applicator_type;
2183 #if variant_CPP11_OR_GREATER
2185 template<
typename Visitor,
typename ... V >
2186 inline auto visit(Visitor
const& v, V
const& ... vars) ->
typename detail::VisitorImpl<
sizeof ... (V), Visitor, V... > ::result_type
2188 typedef detail::VisitorImpl<sizeof ... (V), Visitor, V... > impl_type;
2189 return impl_type::applicator_type::apply(v, vars...);
2193 template<
typename R,
typename Visitor,
typename V1 >
2194 inline R
visit(
const Visitor& v, V1
const& arg1)
2199 template<
typename R,
typename Visitor,
typename V1,
typename V2 >
2200 inline R
visit(
const Visitor& v, V1
const& arg1, V2
const& arg2)
2205 template<
typename R,
typename Visitor,
typename V1,
typename V2,
typename V3 >
2206 inline R
visit(
const Visitor& v, V1
const& arg1, V2
const& arg2, V3
const& arg3)
2211 template<
typename R,
typename Visitor,
typename V1,
typename V2,
typename V3,
typename V4 >
2212 inline R
visit(
const Visitor& v, V1
const& arg1, V2
const& arg2, V3
const& arg3, V4
const& arg4)
2217 template<
typename R,
typename Visitor,
typename V1,
typename V2,
typename V3,
typename V4,
typename V5 >
2218 inline R
visit(
const Visitor& v, V1
const& arg1, V2
const& arg2, V3
const& arg3, V4
const& arg4, V5
const& arg5)
2229 template<
class Variant >
2232 static inline bool equal( Variant
const & v, Variant
const & w )
2236 case 0:
return get<0>( v ) == get<0>( w );
2237 case 1:
return get<1>( v ) == get<1>( w );
2238 case 2:
return get<2>( v ) == get<2>( w );
2239 case 3:
return get<3>( v ) == get<3>( w );
2240 case 4:
return get<4>( v ) == get<4>( w );
2241 case 5:
return get<5>( v ) == get<5>( w );
2242 case 6:
return get<6>( v ) == get<6>( w );
2243 case 7:
return get<7>( v ) == get<7>( w );
2244 case 8:
return get<8>( v ) == get<8>( w );
2245 case 9:
return get<9>( v ) == get<9>( w );
2246 case 10:
return get<10>( v ) == get<10>( w );
2247 case 11:
return get<11>( v ) == get<11>( w );
2248 case 12:
return get<12>( v ) == get<12>( w );
2249 case 13:
return get<13>( v ) == get<13>( w );
2250 case 14:
return get<14>( v ) == get<14>( w );
2251 case 15:
return get<15>( v ) == get<15>( w );
2253 default:
return false;
2257 static inline bool less_than( Variant
const & v, Variant
const & w )
2261 case 0:
return get<0>( v ) < get<0>( w );
2262 case 1:
return get<1>( v ) < get<1>( w );
2263 case 2:
return get<2>( v ) < get<2>( w );
2264 case 3:
return get<3>( v ) < get<3>( w );
2265 case 4:
return get<4>( v ) < get<4>( w );
2266 case 5:
return get<5>( v ) < get<5>( w );
2267 case 6:
return get<6>( v ) < get<6>( w );
2268 case 7:
return get<7>( v ) < get<7>( w );
2269 case 8:
return get<8>( v ) < get<8>( w );
2270 case 9:
return get<9>( v ) < get<9>( w );
2271 case 10:
return get<10>( v ) < get<10>( w );
2272 case 11:
return get<11>( v ) < get<11>( w );
2273 case 12:
return get<12>( v ) < get<12>( w );
2274 case 13:
return get<13>( v ) < get<13>( w );
2275 case 14:
return get<14>( v ) < get<14>( w );
2276 case 15:
return get<15>( v ) < get<15>( w );
2278 default:
return false;
2285 template<
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
2287 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & v,
2288 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & w )
2292 else return detail::Comparator< variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> >::equal( v, w );
2295 template<
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
2297 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & v,
2298 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & w )
2300 return ! ( v == w );
2303 template<
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
2305 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & v,
2306 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & w )
2310 else if ( v.
index() < w.
index() )
return true;
2311 else if ( v.
index() > w.
index() )
return false;
2312 else return detail::Comparator< variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> >::less_than( v, w );
2315 template<
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
2317 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & v,
2318 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & w )
2323 template<
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
2325 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & v,
2326 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & w )
2331 template<
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
2333 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & v,
2334 variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & w )
2341 using namespace variants;
2345 #if variant_CPP11_OR_GREATER
2352 struct hash<
nonstd::monostate >
2360 template<
class T0,
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
class T7,
class T8,
class T9,
class T10,
class T11,
class T12,
class T13,
class T14,
class T15 >
2361 struct hash<
nonstd::variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> >
2363 std::size_t operator()(
nonstd::variant<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> const & v )
const variant_noexcept
2369 case 0:
return nvd::hash( 0 ) ^ nvd::hash( get<0>( v ) );
2370 case 1:
return nvd::hash( 1 ) ^ nvd::hash( get<1>( v ) );
2371 case 2:
return nvd::hash( 2 ) ^ nvd::hash( get<2>( v ) );
2372 case 3:
return nvd::hash( 3 ) ^ nvd::hash( get<3>( v ) );
2373 case 4:
return nvd::hash( 4 ) ^ nvd::hash( get<4>( v ) );
2374 case 5:
return nvd::hash( 5 ) ^ nvd::hash( get<5>( v ) );
2375 case 6:
return nvd::hash( 6 ) ^ nvd::hash( get<6>( v ) );
2376 case 7:
return nvd::hash( 7 ) ^ nvd::hash( get<7>( v ) );
2377 case 8:
return nvd::hash( 8 ) ^ nvd::hash( get<8>( v ) );
2378 case 9:
return nvd::hash( 9 ) ^ nvd::hash( get<9>( v ) );
2379 case 10:
return nvd::hash( 10 ) ^ nvd::hash( get<10>( v ) );
2380 case 11:
return nvd::hash( 11 ) ^ nvd::hash( get<11>( v ) );
2381 case 12:
return nvd::hash( 12 ) ^ nvd::hash( get<12>( v ) );
2382 case 13:
return nvd::hash( 13 ) ^ nvd::hash( get<13>( v ) );
2383 case 14:
return nvd::hash( 14 ) ^ nvd::hash( get<14>( v ) );
2384 case 15:
return nvd::hash( 15 ) ^ nvd::hash( get<15>( v ) );
2386 default:
return false;
2393 #endif // variant_CPP11_OR_GREATER
2395 #if variant_BETWEEN( variant_COMPILER_MSVC_VER, 1300, 1900 )
2396 # pragma warning( pop )
2399 #endif // variant_USES_STD_VARIANT
2401 #endif // NONSTD_VARIANT_LITE_HPP