26#include "vari/bits/typelist.h"
27#include "vari/bits/util.h"
34template <
typename TL >
38 !std::same_as< TL, TL >,
39 "val_union<T> created with unacceptable type - only typelist is allowed" );
42template <
typename... Ts >
43union _val_union< typelist< Ts... > >
45 static constexpr index_type size =
sizeof...( Ts );
47 _val_union() noexcept {};
50 using s1 = split< typelist< Ts... > >;
51 using s2 = split< typename s1::lh >;
52 using s3 = split< typename s1::rh >;
54 using b0 = _val_union< typename s2::lh >;
55 using b1 = _val_union< typename s2::rh >;
56 using b2 = _val_union< typename s3::lh >;
57 using b3 = _val_union< typename s3::rh >;
64 template < index_type i >
65 constexpr static auto& get(
auto& s )
67 if constexpr ( i < b0::size )
68 return b0::template get< i >( s.box0 );
69 else if constexpr ( i < b0::size + b1::size )
70 return b1::template get< i - b0::size >( s.box1 );
71 else if constexpr ( i < b0::size + b1::size + b2::size )
72 return b2::template get< i - b0::size - b1::size >( s.box2 );
73 else if constexpr ( i < b0::size + b1::size + b2::size + b3::size )
74 return b3::template get< i - b0::size - b1::size - b2::size >( s.box3 );
79union _val_union< typelist<> >
81 static constexpr index_type size = 0;
86 ~_val_union() noexcept
90 template < index_type i >
91 constexpr static auto& get(
auto& s )
99template <
typename T0 >
100union _val_union< typelist< T0 > >
102 static constexpr index_type size = 1;
104 _val_union() noexcept
107 ~_val_union() noexcept
114 template < index_type i >
115 constexpr static auto& get(
auto& s )
117 if constexpr ( i == 0 )
123template <
typename T0,
typename T1 >
124union _val_union< typelist< T0, T1 > >
126 static constexpr index_type size = 2;
128 _val_union() noexcept
131 ~_val_union() noexcept
139 template < index_type i >
140 constexpr static auto& get(
auto& s )
142 if constexpr ( i == 0 )
144 if constexpr ( i == 1 )
150template <
typename T0,
typename T1,
typename T2 >
151union _val_union< typelist< T0, T1, T2 > >
153 static constexpr index_type size = 3;
155 _val_union() noexcept
158 ~_val_union() noexcept
167 template < index_type i >
168 constexpr static auto& get(
auto& s )
170 if constexpr ( i == 0 )
172 if constexpr ( i == 1 )
174 if constexpr ( i == 2 )
180template <
typename T0,
typename T1,
typename T2,
typename T3 >
181union _val_union< typelist< T0, T1, T2, T3 > >
183 static constexpr index_type size = 4;
185 _val_union() noexcept
188 ~_val_union() noexcept
198 template < index_type i >
199 constexpr static auto& get(
auto& s )
201 if constexpr ( i == 0 )
203 if constexpr ( i == 1 )
205 if constexpr ( i == 2 )
207 if constexpr ( i == 3 )
213template <
typename T0,
typename T1,
typename T2,
typename T3,
typename T4 >
214union _val_union< typelist< T0, T1, T2, T3, T4 > >
216 static constexpr index_type size = 5;
218 _val_union() noexcept
221 ~_val_union() noexcept
232 template < index_type i >
233 constexpr static auto& get(
auto& s )
235 if constexpr ( i == 0 )
237 if constexpr ( i == 1 )
239 if constexpr ( i == 2 )
241 if constexpr ( i == 3 )
243 if constexpr ( i == 4 )
249template <
typename T0,
typename T1,
typename T2,
typename T3,
typename T4,
typename T5 >
250union _val_union< typelist< T0, T1, T2, T3, T4, T5 > >
252 static constexpr index_type size = 6;
254 _val_union() noexcept
257 ~_val_union() noexcept
269 template < index_type i >
270 constexpr static auto& get(
auto& s )
272 if constexpr ( i == 0 )
274 if constexpr ( i == 1 )
276 if constexpr ( i == 2 )
278 if constexpr ( i == 3 )
280 if constexpr ( i == 4 )
282 if constexpr ( i == 5 )
296union _val_union< typelist< T0, T1, T2, T3, T4, T5, T6 > >
298 static constexpr index_type size = 7;
300 _val_union() noexcept
303 ~_val_union() noexcept
316 template < index_type i >
317 constexpr static auto& get(
auto& s )
319 if constexpr ( i == 0 )
321 if constexpr ( i == 1 )
323 if constexpr ( i == 2 )
325 if constexpr ( i == 3 )
327 if constexpr ( i == 4 )
329 if constexpr ( i == 5 )
331 if constexpr ( i == 6 )
346union _val_union< typelist< T0, T1, T2, T3, T4, T5, T6, T7 > >
348 static constexpr index_type size = 8;
350 _val_union() noexcept
353 ~_val_union() noexcept
367 template < index_type i >
368 constexpr static auto& get(
auto& s )
370 if constexpr ( i == 0 )
372 if constexpr ( i == 1 )
374 if constexpr ( i == 2 )
376 if constexpr ( i == 3 )
378 if constexpr ( i == 4 )
380 if constexpr ( i == 5 )
382 if constexpr ( i == 6 )
384 if constexpr ( i == 7 )
400union _val_union< typelist< T0, T1, T2, T3, T4, T5, T6, T7, T8 > >
402 static constexpr index_type size = 9;
404 _val_union() noexcept
407 ~_val_union() noexcept
422 template < index_type i >
423 constexpr static auto& get(
auto& s )
425 if constexpr ( i == 0 )
427 if constexpr ( i == 1 )
429 if constexpr ( i == 2 )
431 if constexpr ( i == 3 )
433 if constexpr ( i == 4 )
435 if constexpr ( i == 5 )
437 if constexpr ( i == 6 )
439 if constexpr ( i == 7 )
441 if constexpr ( i == 8 )
458union _val_union< typelist< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 > >
460 static constexpr index_type size = 10;
462 _val_union() noexcept
465 ~_val_union() noexcept
481 template < index_type i >
482 constexpr static auto& get(
auto& s )
484 if constexpr ( i == 0 )
486 if constexpr ( i == 1 )
488 if constexpr ( i == 2 )
490 if constexpr ( i == 3 )
492 if constexpr ( i == 4 )
494 if constexpr ( i == 5 )
496 if constexpr ( i == 6 )
498 if constexpr ( i == 7 )
500 if constexpr ( i == 8 )
502 if constexpr ( i == 9 )
520union _val_union< typelist< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10 > >
522 static constexpr index_type size = 11;
524 _val_union() noexcept
527 ~_val_union() noexcept
544 template < index_type i >
545 constexpr static auto& get(
auto& s )
547 if constexpr ( i == 0 )
549 if constexpr ( i == 1 )
551 if constexpr ( i == 2 )
553 if constexpr ( i == 3 )
555 if constexpr ( i == 4 )
557 if constexpr ( i == 5 )
559 if constexpr ( i == 6 )
561 if constexpr ( i == 7 )
563 if constexpr ( i == 8 )
565 if constexpr ( i == 9 )
567 if constexpr ( i == 10 )
586union _val_union< typelist< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 > >
588 static constexpr index_type size = 12;
590 _val_union() noexcept
593 ~_val_union() noexcept
611 template < index_type i >
612 constexpr static auto& get(
auto& s )
614 if constexpr ( i == 0 )
616 if constexpr ( i == 1 )
618 if constexpr ( i == 2 )
620 if constexpr ( i == 3 )
622 if constexpr ( i == 4 )
624 if constexpr ( i == 5 )
626 if constexpr ( i == 6 )
628 if constexpr ( i == 7 )
630 if constexpr ( i == 8 )
632 if constexpr ( i == 9 )
634 if constexpr ( i == 10 )
636 if constexpr ( i == 11 )
656union _val_union< typelist< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12 > >
658 static constexpr index_type size = 13;
660 _val_union() noexcept
663 ~_val_union() noexcept
682 template < index_type i >
683 constexpr static auto& get(
auto& s )
685 if constexpr ( i == 0 )
687 if constexpr ( i == 1 )
689 if constexpr ( i == 2 )
691 if constexpr ( i == 3 )
693 if constexpr ( i == 4 )
695 if constexpr ( i == 5 )
697 if constexpr ( i == 6 )
699 if constexpr ( i == 7 )
701 if constexpr ( i == 8 )
703 if constexpr ( i == 9 )
705 if constexpr ( i == 10 )
707 if constexpr ( i == 11 )
709 if constexpr ( i == 12 )
730union _val_union< typelist< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13 > >
732 static constexpr index_type size = 14;
734 _val_union() noexcept
737 ~_val_union() noexcept
757 template < index_type i >
758 constexpr static auto& get(
auto& s )
760 if constexpr ( i == 0 )
762 if constexpr ( i == 1 )
764 if constexpr ( i == 2 )
766 if constexpr ( i == 3 )
768 if constexpr ( i == 4 )
770 if constexpr ( i == 5 )
772 if constexpr ( i == 6 )
774 if constexpr ( i == 7 )
776 if constexpr ( i == 8 )
778 if constexpr ( i == 9 )
780 if constexpr ( i == 10 )
782 if constexpr ( i == 11 )
784 if constexpr ( i == 12 )
786 if constexpr ( i == 13 )
808union _val_union< typelist< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14 > >
810 static constexpr index_type size = 15;
812 _val_union() noexcept
815 ~_val_union() noexcept
836 template < index_type i >
837 constexpr static auto& get(
auto& s )
839 if constexpr ( i == 0 )
841 if constexpr ( i == 1 )
843 if constexpr ( i == 2 )
845 if constexpr ( i == 3 )
847 if constexpr ( i == 4 )
849 if constexpr ( i == 5 )
851 if constexpr ( i == 6 )
853 if constexpr ( i == 7 )
855 if constexpr ( i == 8 )
857 if constexpr ( i == 9 )
859 if constexpr ( i == 10 )
861 if constexpr ( i == 11 )
863 if constexpr ( i == 12 )
865 if constexpr ( i == 13 )
867 if constexpr ( i == 14 )
890union _val_union< typelist< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 > >
892 static constexpr index_type size = 16;
894 _val_union() noexcept
897 ~_val_union() noexcept
919 template < index_type i >
920 constexpr static auto& get(
auto& s )
922 if constexpr ( i == 0 )
924 if constexpr ( i == 1 )
926 if constexpr ( i == 2 )
928 if constexpr ( i == 3 )
930 if constexpr ( i == 4 )
932 if constexpr ( i == 5 )
934 if constexpr ( i == 6 )
936 if constexpr ( i == 7 )
938 if constexpr ( i == 8 )
940 if constexpr ( i == 9 )
942 if constexpr ( i == 10 )
944 if constexpr ( i == 11 )
946 if constexpr ( i == 12 )
948 if constexpr ( i == 13 )
950 if constexpr ( i == 14 )
952 if constexpr ( i == 15 )
MIT License.
Definition: dispatch.h:32