summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-05-07 11:13:21 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-05-10 11:19:22 +0200
commitd561e59cacc4e22cb5fb87c3fee09c7c50c7dde2 (patch)
tree39685d03a68080bf2f12aca2479b4415b2f3a66f /compat
parent940ae0898c5e836c3d82fac85f5fa55bb75414a1 (diff)
meta: add index sequence with types as indices
Diffstat (limited to 'compat')
-rw-r--r--compat/meta.hpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/compat/meta.hpp b/compat/meta.hpp
index b1c1dd1a..900c515f 100644
--- a/compat/meta.hpp
+++ b/compat/meta.hpp
@@ -1,6 +1,8 @@
#pragma once
+#include <type_traits>
#include <tuple>
+#include <cstddef>
namespace meta {
@@ -29,7 +31,20 @@ namespace detail {
{
using type = inst<xs...>;
};
-}
+
+ template<typename N, N max, N pos, typename... xs>
+ struct index_sequence_
+ {
+ using part = std::integral_constant<N, pos>;
+ using type = typename index_sequence_<N, max, pos+1, xs..., part>::type;
+ };
+
+ template<typename N, N max, typename... xs>
+ struct index_sequence_<N, max, max, xs...>
+ {
+ using type = std::tuple<xs...>;
+ };
+} // ns detail
template<typename... xs>
@@ -50,4 +65,7 @@ using butlast = reverse<rest<reverse<xs...>>>;
template<typename... xs>
using last = lift<first, reverse<xs...>>;
-}
+template<std::size_t max>
+using index_sequence = typename detail::index_sequence_<std::size_t, max, std::size_t(0)>::type;
+
+} // ns meta