I have trouble understand this section of the code. I know it generate a sequence of numbers, Its from https://stackoverflow.com/a/24481400/403360
But I can't make a logic out of this, I need some guide line to walk through this. especially why N-1, N-1
?
template <size_t ...I>
struct index_sequence {};
template <size_t N, size_t ...I>
struct make_index_sequence : public make_index_sequence<N - 1, N - 1, I...> {};
template <size_t ...I>
struct make_index_sequence<0, I...> : public index_sequence<I...> {};
and whats the effect of the make_index_sequence<sizeof...(T)>()
does to the do_foo_helper
? It seems it just passing to the function without a name, and something would help.
template<typename ...T, size_t ...I>
/* ... */ do_foo_helper(std::tuple<T...> &ts, index_sequence<I...>) {
std::tie(foo(std::get<I>(ts)) ...);
}
template <typename ...T>
/* ... */ do_foo(std::tuple<T...> &ts) {
return do_foo_helper(ts, make_index_sequence<sizeof...(T)>());
}