Skip to content

Instantly share code, notes, and snippets.

@windoze
Created December 9, 2014 15:22
Show Gist options
  • Save windoze/6500832f435df0c87951 to your computer and use it in GitHub Desktop.
Save windoze/6500832f435df0c87951 to your computer and use it in GitHub Desktop.
make_tuple_indices extracts elements from tuple
template <std::size_t...> struct tuple_indices {};
template <std::size_t Sp, class IntTuple, std::size_t Ep> struct make_indices_imp;
template <std::size_t Sp, std::size_t... Indices, std::size_t Ep>
struct make_indices_imp<Sp, tuple_indices<Indices...>, Ep>
{ typedef typename make_indices_imp<Sp+1, tuple_indices<Indices..., Sp>, Ep>::type type; };
template <std::size_t Ep, std::size_t... Indices>
struct make_indices_imp<Ep, tuple_indices<Indices...>, Ep>
{ typedef tuple_indices<Indices...> type; };
template <std::size_t Ep, std::size_t Sp = 0>
struct make_tuple_indices {
static_assert(Sp <= Ep, "make_tuple_indices input error");
typedef typename make_indices_imp<Sp, tuple_indices<>, Ep>::type type;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment