summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-02-28 17:08:19 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-02-28 17:08:19 +0000
commitf88e873f55362bdc85b1461cf573e8cd3fc087fa (patch)
tree765d61926b9f4650e4cbb1ad59f06ca6998347d8 /src
parent31267675b960fb4020af12f6b2479eaf040a3b74 (diff)
Add IndexSequence and make_index_sequence utilities
Diffstat (limited to 'src')
-rw-r--r--src/utils.hh22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils.hh b/src/utils.hh
index fbf39e10..c441cdf3 100644
--- a/src/utils.hh
+++ b/src/utils.hh
@@ -14,6 +14,28 @@ std::unique_ptr<T> make_unique(Args&&... args)
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
+template<size_t... I>
+struct IndexSequence
+{
+ using Next = IndexSequence<I..., sizeof...(I)>;
+};
+
+template<size_t N>
+struct MakeIndexSequence
+{
+ using Type = typename MakeIndexSequence<N-1>::Type::Next;
+};
+
+template<>
+struct MakeIndexSequence<0>
+{
+ using Type = IndexSequence<>;
+};
+
+template<size_t N>
+constexpr typename MakeIndexSequence<N>::Type
+make_index_sequence() { return typename MakeIndexSequence<N>::Type{}; }
+
// *** Singleton ***
//
// Singleton helper class, every singleton type T should inherit