Last active
February 1, 2016 11:42
-
-
Save hatsusato/4c5b80ee46f1ab90281f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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