1 #ifndef VCSN_MISC_TUPLE_HH
2 # define VCSN_MISC_TUPLE_HH
29 template<
class S1,
class S2>
struct concat;
31 template<std::size_t... I1, std::size_t... I2>
35 template<
class S1,
class S2>
39 template<std::
size_t N>
using GenSeq =
42 template<std::
size_t N>
48 template<std::
size_t off,
class S2>
struct int_range;
50 template<std::size_t off, std::size_t... I>
54 template<std::
size_t S, std::
size_t L>
56 :
int_range<S, typename make_index_sequence<L>::type>{};
58 template<std::
size_t S>
60 template<std::
size_t S>
63 template<
typename S1,
typename S2>
66 template<std::size_t... I1, std::size_t... I2>
70 template <
typename S1,
typename S2>
81 template <
typename Fun,
typename... Ts>
83 for_(
const std::tuple<Ts...>& ts, Fun f)
88 template <
typename Fun,
typename... Ts,
size_t... I>
91 const std::tuple<Ts...>& ts,
94 using swallow =
int[];
95 (void) swallow{ (f(std::get<I>(ts)), 0)... };
99 template <
typename Fun,
typename... Ts>
101 map(
const std::tuple<Ts...>& ts, Fun f)
107 template <
typename Fun,
typename... Ts,
size_t... I>
110 const std::tuple<Ts...>& ts,
117 template<
typename Fun>
120 -> decltype(std::make_tuple())
122 return std::make_tuple();
125 template <
typename Fun,
typename T,
typename... Ts>
128 -> decltype(std::tuple_cat(std::make_tuple(f(t)),
map_variadic_(f, ts...)))
132 return std::tuple_cat(std::make_tuple(
r),
map_variadic_(f, ts...));
152 template <
typename T,
typename... Ts>
155 -> decltype(std::tuple_cat(
make_gcc_tuple(std::forward<Ts>(ts)...), std::make_tuple(t)));
157 template <
typename T,
typename... Ts>
160 -> decltype(std::tuple_cat(
make_gcc_tuple(std::forward<Ts>(ts)...), std::make_tuple(t)))
162 return std::tuple_cat(
make_gcc_tuple(std::forward<Ts>(ts)...), std::make_tuple(t));
172 template <
typename... Ts>
180 template <
typename... Ts, std::size_t... I>
183 -> decltype(std::make_tuple(std::get<
sizeof...(Ts) - 1 - I>(t)...))
185 return std::make_tuple(std::get<
sizeof...(Ts) - 1 - I>(t)...);
190 # if VCSN_HAVE_CORRECT_LIST_INITIALIZER_ORDER
191 template <
typename... Ts>
194 -> decltype(std::make_tuple(std::forward<Ts>(ts)...))
196 return std::make_tuple(std::forward<Ts>(ts)...);
199 template <
typename... Ts>
202 -> decltype(
reverse_tuple(std::make_tuple(std::forward<Ts>(ts)...)))
204 return reverse_tuple(std::make_tuple(std::forward<Ts>(ts)...));
213 template<
class Tuple, std::
size_t N>
216 static void print(
const Tuple& t, std::ostream& o)
219 o <<
", " << std::get<N-1>(t);
223 template<
class Tuple>
226 static void print(
const Tuple& t, std::ostream& o)
232 template <
typename... Args>
233 std::ostream&
print(
const std::tuple<Args...>& args, std::ostream& o)
246 template<
bool c,
class T1,
class T2>
249 template<
class T1,
class T2>
252 template<
class C,
class T1,
class T2>
256 template<
bool c,
class F1,
class F2>
259 template<
class C,
class F1,
class F2>
266 template<
class F1,
class... F>
267 struct and_<F1, F...> :
eval_if<F1, and_<F...>, std::false_type>::type {};
270 struct and_<F1> :
eval_if<F1, std::true_type, std::false_type>::type {};
279 template<
class F1,
class... F>
280 struct or_<F1, F...> :
eval_if<F1, std::true_type, or_<F...>>::type { };
283 struct or_<F1> :
eval_if<F1, std::true_type, std::false_type>::type { };
313 template <
typename... Elements>
314 struct hash<std::tuple<Elements...>>
325 template <std::size_t... I>
330 using swallow =
int[];
333 (std::hash_combine(res, std::get<I>(v)), 0)...
340 #endif // !VCSN_MISC_TUPLE_HH
typename concat_index_sequence< S1, S2 >::type concat_sequence
std::tuple< Elements...> value_t
std::size_t operator()(const value_t &v) const
static std::size_t hash_(const value_t &v, vcsn::detail::index_sequence< I...>)
static void print(const Tuple &t, std::ostream &o)
auto map_variadic_(Fun) -> decltype(std::make_tuple())
void for_(const std::tuple< Ts...> &ts, Fun f)
auto map_tuple_(Fun f, const std::tuple< Ts...> &ts, index_sequence< I...>) -> decltype(map_variadic_(f, std::get< I >(ts)...))
constexpr bool any_()
Static evaluation of the 'or' of the template parameters.
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.
auto reverse_tuple(const std::tuple< Ts...> &t) -> decltype(reverse_tuple(t, make_index_sequence< sizeof...(Ts)>()))
Provide a variadic mul on top of a binary mul(), and one().
typename make_index_sequence< N >::type GenSeq
static void print(const Tuple &t, std::ostream &o)
std::ostream & print(const std::tuple< Args...> &args, std::ostream &o)
auto make_gcc_tuple(Ts &&...ts) -> decltype(reverse_tuple(std::make_tuple(std::forward< Ts >(ts)...)))
Same as make_tuple, unless the evaluation of arguments if right-to-left, in which case reverse the re...