From ef7a777660034a142f24a5edc63d06f25d4d0562 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 29 Apr 2017 16:05:09 +0200 Subject: compat/meta: add basic template metaprogramming header --- compat/meta.hpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ compat/util.hpp | 1 + 2 files changed, 54 insertions(+) create mode 100644 compat/meta.hpp diff --git a/compat/meta.hpp b/compat/meta.hpp new file mode 100644 index 00000000..b1c1dd1a --- /dev/null +++ b/compat/meta.hpp @@ -0,0 +1,53 @@ +#pragma once + +#include + +namespace meta { + +namespace detail { + + template + struct reverse_; + + template class x, typename... ys> + struct reverse_, x> + { + using type = typename reverse_, x>::type; + }; + + template class x, typename... ys> + struct reverse_, x> + { + using type = x; + }; + + template class inst, typename x> + struct lift_; + + template class inst, template class x, typename... xs> + struct lift_> + { + using type = inst; + }; +} + + +template +using reverse = typename detail::reverse_, std::tuple<>>::type; + +template class inst, class x> +using lift = typename detail::lift_::type; + +template +using first = x; + +template +using rest = std::tuple; + +template +using butlast = reverse>>; + +template +using last = lift>; + +} diff --git a/compat/util.hpp b/compat/util.hpp index 60427b53..3adebd5b 100644 --- a/compat/util.hpp +++ b/compat/util.hpp @@ -2,6 +2,7 @@ #include "ndebug-guard.hpp" #include "run-in-thread.hpp" +#include "meta.hpp" #include #include -- cgit v1.2.3