17 #ifndef AWALI_TUPLE_HH
18 # define AWALI_TUPLE_HH
45 template<
class S1,
class S2>
struct concat;
47 template<std::size_t... I1, std::size_t... I2>
51 template<
class S1,
class S2>
55 template<std::
size_t N>
using GenSeq =
58 template<std::
size_t N>
66 template<std::size_t... I1, std::size_t... I2>
71 template<
size_t I1,
size_t... I2>
81 template<std::
size_t off,
class S2>
struct int_range;
83 template<std::size_t off, std::size_t... I>
87 template<std::
size_t S, std::
size_t L>
89 :
int_range<S, typename make_index_sequence<L>::type>{};
91 template<std::
size_t S>
93 template<std::
size_t S>
96 template<
typename S1,
typename S2>
99 template<std::size_t... I1, std::size_t... I2>
103 template <
typename S1,
typename S2>
114 template <
typename Fun,
typename... Ts>
116 for_(
const std::tuple<Ts...>& ts, Fun f)
121 template <
typename Fun,
typename... Ts,
size_t... I>
124 const std::tuple<Ts...>& ts,
127 using swallow =
int[];
128 (void) swallow{ (f(std::get<I>(ts)), 0)... };
132 template <
typename Fun,
typename... Ts>
134 map(
const std::tuple<Ts...>& ts, Fun f)
140 template <
typename Fun,
typename... Ts,
size_t... I>
143 const std::tuple<Ts...>& ts,
150 template<
typename Fun>
153 -> decltype(std::make_tuple())
155 return std::make_tuple();
158 template <
typename Fun,
typename T,
typename... Ts>
161 -> decltype(std::tuple_cat(std::make_tuple(f(t)),
map_variadic_(f, ts...)))
165 return std::tuple_cat(std::make_tuple(r),
map_variadic_(f, ts...));
185 template <
typename T,
typename... Ts>
188 -> decltype(std::tuple_cat(
make_inv_tuple(std::forward<Ts>(ts)...), std::make_tuple(t)));
190 template <
typename T,
typename... Ts>
193 -> decltype(std::tuple_cat(
make_inv_tuple(std::forward<Ts>(ts)...), std::make_tuple(t)))
195 return std::tuple_cat(
make_inv_tuple(std::forward<Ts>(ts)...), std::make_tuple(t));
205 template <
typename... Ts>
213 template <
typename... Ts, std::size_t... I>
216 -> decltype(std::make_tuple(std::get<
sizeof...(Ts) - 1 - I>(t)...))
218 return std::make_tuple(std::get<
sizeof...(Ts) - 1 - I>(t)...);
221 template <
typename... Ts>
224 -> decltype(
reverse_tuple(std::make_tuple(std::forward<Ts>(ts)...)))
226 return reverse_tuple(std::make_tuple(std::forward<Ts>(ts)...));
234 template<
class Tuple, std::
size_t N>
237 static void print(
const Tuple& t, std::ostream& o)
240 o <<
", " << std::get<N-1>(t);
244 template<
class Tuple>
247 static void print(
const Tuple& t, std::ostream& o)
253 template <
typename... Args>
254 std::ostream&
print(
const std::tuple<Args...>& args, std::ostream& o)
266 template<
bool c,
class T1,
class T2>
269 template<
class T1,
class T2>
272 template<
class C,
class T1,
class T2>
276 template<
bool c,
class F1,
class F2>
279 template<
class C,
class F1,
class F2>
286 template<
class F1,
class... F>
287 struct and_<F1, F...> :
eval_if<F1, and_<F...>, std::false_type>::type {};
290 struct and_<F1> :
eval_if<F1, std::true_type, std::false_type>::type {};
293 struct and_<> : std::true_type::type {};
299 template<
class F1,
class... F>
300 struct or_<F1, F...> :
eval_if<F1, std::true_type, or_<F...>>::type { };
303 struct or_<F1> :
eval_if<F1, std::true_type, std::false_type>::type { };
306 struct or_<> : std::true_type::type {};
333 template <
typename... Elements>
334 struct hash<std::tuple<Elements...>>
345 template <std::size_t... I>
350 using swallow =
int[];
360 template<
typename T1,
typename... T2>
362 using type = std::tuple<T1,T2...>;
366 template<
typename... T1,
typename... T2>
368 using type = std::tuple<T1...,T2...>;
371 template<
typename T,
unsigned N>
385 template <
typename... Args>
386 std::ostream& operator<<(std::ostream& o,
const std::tuple<Args...>& args)
auto map(const std::tuple< Ts... > &ts, Fun f) -> decltype(map_tuple_(f, ts, make_index_sequence< sizeof...(Ts)>()))
Map a function on a tuple, return tuple of the results.
Definition: tuple.hh:134
typename seqconcat< typename reverseseq< index_sequence< I2... > >::type, index_sequence< I1 > >::type type
Definition: tuple.hh:74
typename concat_index_sequence< S1, S2 >::type concat_sequence
Definition: tuple.hh:104
auto map_variadic_(Fun) -> decltype(std::make_tuple())
Definition: tuple.hh:152
typename concat< S1, S2 >::type Concat
Definition: tuple.hh:52
T1 type
Definition: tuple.hh:267
auto map_tuple_(Fun f, const std::tuple< Ts... > &ts, index_sequence< I... >) -> decltype(map_variadic_(f, std::get< I >(ts)...))
Definition: tuple.hh:142
auto reverse_tuple(const std::tuple< Ts... > &t) -> decltype(reverse_tuple(t, make_index_sequence< sizeof...(Ts)>()))
Definition: tuple.hh:207
auto make_inv_tuple() -> std::tuple<>
Definition: tuple.hh:179
void for_(const std::tuple< Ts... > &ts, Fun f)
Definition: tuple.hh:116
typename make_index_sequence< N >::type GenSeq
Definition: tuple.hh:56
T2 type
Definition: tuple.hh:270
std::ostream & print(const std::tuple< Args... > &args, std::ostream &o)
Definition: tuple.hh:254
static constexpr TOP< void > value
Definition: priority.hh:93
Main namespace of Awali.
Definition: ato.hh:22
constexpr bool any_()
Static evaluation of the 'or' of the template parameters.
Definition: tuple.hh:311
constexpr bool all_()
Definition: tuple.hh:318
static void print(const Tuple &t, std::ostream &o)
Definition: tuple.hh:247
static void print(const Tuple &t, std::ostream &o)
Definition: tuple.hh:237
std::tuple< T1..., T2... > type
Definition: tuple.hh:368
std::tuple< T1, T2... > type
Definition: tuple.hh:362
std::tuple< T > type
Definition: tuple.hh:378
typename cons_tuple< T, typename cst_tuple< T, N-1 >::type >::type type
Definition: tuple.hh:373
std::size_t operator()(const value_t &v) const
Definition: tuple.hh:339
std::tuple< Elements... > value_t
Definition: tuple.hh:336
void hash_combine(std::size_t &seed, const T &v)
Definition: hash.hh:27