1 | /*
|
---|
2 | * Copyright (c) 2018 Jaroslav Jindrak
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef LIBCPP_BITS_TUPLE_TUPLE_CAT
|
---|
30 | #define LIBCPP_BITS_TUPLE_TUPLE_CAT
|
---|
31 |
|
---|
32 | #include <utility>
|
---|
33 |
|
---|
34 | namespace std
|
---|
35 | { // forward declarations
|
---|
36 | template<class... Ts>
|
---|
37 | struct tuple;
|
---|
38 |
|
---|
39 | template<size_t I, class T>
|
---|
40 | struct tuple_element;
|
---|
41 |
|
---|
42 | template<size_t I, class... Ts>
|
---|
43 | constexpr typename tuple_element<I, tuple<Ts...>>::type& get(tuple<Ts...>& tpl) noexcept;
|
---|
44 |
|
---|
45 | template<class T, T...>
|
---|
46 | struct integer_sequence;
|
---|
47 |
|
---|
48 | template<size_t... Is>
|
---|
49 | using index_sequence = integer_sequence<size_t, Is...>;
|
---|
50 | }
|
---|
51 |
|
---|
52 | namespace std::aux
|
---|
53 | {
|
---|
54 | template<class...>
|
---|
55 | struct tuple_append;
|
---|
56 |
|
---|
57 | template<class... Ts, class... Us, class... Vs>
|
---|
58 | struct tuple_append<tuple<Ts...>, tuple<Us...>, Vs...>
|
---|
59 | : type_is<tuple<Ts..., Us...>>
|
---|
60 | { /* DUMMY BODY */ };
|
---|
61 |
|
---|
62 | template<class... Ts>
|
---|
63 | using tuple_append_t = typename tuple_append<Ts...>::type;
|
---|
64 |
|
---|
65 | template<class...>
|
---|
66 | struct remove_first_tuple;
|
---|
67 |
|
---|
68 | template<class... Ts, class... Tuples>
|
---|
69 | struct remove_first_tuple<tuple<Ts...>, Tuples...>
|
---|
70 | : type_is<Tuples...>
|
---|
71 | { /* DUMMY BODY */ };
|
---|
72 |
|
---|
73 | template<class... Ts>
|
---|
74 | using remove_first_tuple_t = typename remove_first_tuple<Ts...>::type;
|
---|
75 |
|
---|
76 | template<class...>
|
---|
77 | struct get_first_tuple;
|
---|
78 |
|
---|
79 | template<class... Ts, class... Tuples>
|
---|
80 | struct get_first_tuple<tuple<Ts...>, Tuples...>
|
---|
81 | : type_is<tuple<Ts...>>
|
---|
82 | { /* DUMMY BODY */ };
|
---|
83 |
|
---|
84 | template<class... Ts>
|
---|
85 | using get_first_tuple_t = typename get_first_tuple<Ts...>::type;
|
---|
86 |
|
---|
87 | template<class...>
|
---|
88 | struct tuple_cat_type_impl;
|
---|
89 |
|
---|
90 | template<class... Ts, class... Tuples>
|
---|
91 | struct tuple_cat_type_impl<tuple<Ts...>, Tuples...>
|
---|
92 | : type_is<
|
---|
93 | typename tuple_cat_type_impl<
|
---|
94 | tuple_append_t<tuple<Ts...>, get_first_tuple_t<Tuples...>>,
|
---|
95 | remove_first_tuple_t<Tuples...>
|
---|
96 | >::type
|
---|
97 | >
|
---|
98 | { /* DUMMY BODY */ };
|
---|
99 |
|
---|
100 | template<class... Ts>
|
---|
101 | using tuple_cat_type_impl_t = typename tuple_cat_type_impl<Ts...>::type;
|
---|
102 |
|
---|
103 | template<class...>
|
---|
104 | struct tuple_cat_type;
|
---|
105 |
|
---|
106 | template<class... Ts, class... Tuples>
|
---|
107 | struct tuple_cat_type<tuple<Ts...>, Tuples...>
|
---|
108 | : type_is<tuple_cat_type_impl_t<tuple<Ts...>, Tuples...>>
|
---|
109 | { /* DUMMY BODY */ };
|
---|
110 |
|
---|
111 | template<class... Ts>
|
---|
112 | using tuple_cat_type_t = typename tuple_cat_type<Ts...>::type;
|
---|
113 |
|
---|
114 | template<class...>
|
---|
115 | struct concatenate_sequences;
|
---|
116 |
|
---|
117 | template<size_t... Is1, size_t... Is2>
|
---|
118 | struct concatenate_sequences<index_sequence<Is1...>, index_sequence<Is2...>>
|
---|
119 | : type_is<index_sequence<Is1..., Is2...>>
|
---|
120 | { /* DUMMY BODY */ };
|
---|
121 |
|
---|
122 | template<class... Ts>
|
---|
123 | using concatenate_sequences_t = typename concatenate_sequences<Ts...>::type;
|
---|
124 |
|
---|
125 | template<class...>
|
---|
126 | struct append_indices;
|
---|
127 |
|
---|
128 | template<size_t... Is, class... Ts, class... Tuples>
|
---|
129 | struct append_indices<index_sequence<Is...>, tuple<Ts...>, Tuples...>
|
---|
130 | : append_indices<
|
---|
131 | concatenate_sequences_t<
|
---|
132 | index_sequence<Is...>, make_index_sequence<sizeof...(Ts)>
|
---|
133 | >,
|
---|
134 | Tuples...
|
---|
135 | >
|
---|
136 | { /* DUMMY BODY */ };
|
---|
137 |
|
---|
138 | template<class... Ts>
|
---|
139 | using append_indices_t = typename append_indices<Ts...>::types;
|
---|
140 |
|
---|
141 | template<class...>
|
---|
142 | struct generate_indices;
|
---|
143 |
|
---|
144 | template<class... Ts, class... Tuples>
|
---|
145 | struct generate_indices<tuple<Ts...>, Tuples...>
|
---|
146 | : type_is<
|
---|
147 | append_indices_t<
|
---|
148 | make_index_sequence<sizeof...(Ts)>,
|
---|
149 | Tuples...
|
---|
150 | >
|
---|
151 | >
|
---|
152 | { /* DUMMY BODY */ };
|
---|
153 |
|
---|
154 | template<class... Ts>
|
---|
155 | using generate_indices_t = typename generate_indices<Ts...>::type;
|
---|
156 |
|
---|
157 | template<class... Tuples, size_t... Is1, size_t... Is2>
|
---|
158 | tuple_cat_type_t<Tuples...> tuple_cat(Tuples&&... tpls,
|
---|
159 | index_sequence<Is1...>,
|
---|
160 | index_sequence<Is2...>)
|
---|
161 | {
|
---|
162 | return tuple_cat_type_t<Tuples...>{
|
---|
163 | get<Is1...>(
|
---|
164 | get<Is2...>(
|
---|
165 | forward<Tuples>(tpls)
|
---|
166 | )
|
---|
167 | )...
|
---|
168 | };
|
---|
169 | }
|
---|
170 | }
|
---|
171 |
|
---|
172 | #endif
|
---|