Skip to content

Instantly share code, notes, and snippets.

@hatsusato
Last active February 1, 2016 11:42
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 hatsusato/4c5b80ee46f1ab90281f to your computer and use it in GitHub Desktop.
Save hatsusato/4c5b80ee46f1ab90281f to your computer and use it in GitHub Desktop.
// template <class T, T... Ints> class integer_sequence; // in <utility> since C++14
template <size_t... N>
struct IntegerSeq {
using type = IntegerSeq;
static constexpr size_t size() { return sizeof...(N); }
};
template <typename S, typename T>
struct ConcatSeq_;
template <typename S, typename T>
using ConcatSeq = typename ConcatSeq_<S, T>::type;
template <size_t... I, size_t... J>
struct ConcatSeq_<IntegerSeq<I...>, IntegerSeq<J...> >
: IntegerSeq<I..., (sizeof...(I) + J)...> {};
template <size_t N>
struct MakeSeq_;
template <size_t N>
using MakeSeq = typename MakeSeq_<N>::type;
template <>
struct MakeSeq_<0> : IntegerSeq<> {};
template <>
struct MakeSeq_<1> : IntegerSeq<0> {};
template <size_t N>
struct MakeSeq_ : ConcatSeq<MakeSeq<N / 2>, MakeSeq<N - N / 2> > {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment