Skip to content

Instantly share code, notes, and snippets.

@ThePhD
Created July 1, 2014 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThePhD/a4e89a47af937f41bca7 to your computer and use it in GitHub Desktop.
Save ThePhD/a4e89a47af937f41bca7 to your computer and use it in GitHub Desktop.
indices_trick
#pragma once
#include <Furrovine++/unqualified.h>
#include <tuple>
namespace Furrovine {
template <std::size_t... I>
struct indices { typedef indices type; };
template <std::size_t N, std::size_t... I>
struct make_indices : public make_indices<N - 1, N - 1, I...> { };
template <std::size_t... I>
struct make_indices<0, I...> : public indices<I...>{ };
template <std::size_t N, std::size_t... I>
struct make_even_indices : public make_indices<N - 2, N - 2, I...> { };
template <std::size_t... I>
struct make_even_indices<0, I...> : public indices<I...>{ };
template <typename... Tn>
struct types : make_indices<sizeof...( Tn )> { };
template <typename T>
struct tuple_indices : public make_indices<std::tuple_size<typename unqualified<T>::type>::value> { };
template <typename... Tn>
struct tuple_types : types<Tn...>, std::false_type { };
template <typename... Tn>
struct tuple_types<std::tuple<Tn...>> : types<Tn...>, std::true_type{ };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment