diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-07-02 05:07:09 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-07-02 05:07:09 +0200 |
commit | 66e75860d0c54baa39ed789442b09b96eeebe2e6 (patch) | |
tree | 38b78c1233e5be941bce28b6870d8e8cc1251f67 /compat/meta.hpp | |
parent | d6ca17243063dc33381609fa5767aa4f323f1048 (diff) |
compat/meta: try make usable
Diffstat (limited to 'compat/meta.hpp')
-rw-r--r-- | compat/meta.hpp | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/compat/meta.hpp b/compat/meta.hpp index b02029a7..8682fdc8 100644 --- a/compat/meta.hpp +++ b/compat/meta.hpp @@ -7,17 +7,22 @@ * copyright notice and this permission notice appear in all copies. */ -#if 0 - -#include <tuple> -#include <cstddef> +#define OTR_META_INST_FAIL(x) \ + static_assert(sizeof...(x) == ~0ul); \ + static_assert(sizeof...(x) == 0u) namespace meta { namespace detail { - template<typename x, typename y> - struct reverse_; + template<typename... xs> + struct tuple; + + template<typename... xs> + struct reverse_ + { + OTR_META_INST_FAIL(xs); + }; template<typename x0, typename... xs, template<typename...> class x, typename... ys> struct reverse_<x<x0, xs...>, x<ys...>> @@ -31,28 +36,32 @@ namespace detail { using type = x<ys...>; }; - template<template<typename...> class inst, typename x> - struct lift_; + template<template<typename...> class inst, typename... xs> + struct lift_ + { + OTR_META_INST_FAIL(xs); + }; - template<template<typename...> class inst, template<typename...> class x, typename... xs> - struct lift_<inst, x<xs...>> + template<template<typename...> class to, template<typename...> class from, typename... xs> + struct lift_<to, from<xs...>> { - using type = inst<xs...>; + using type = to<xs...>; }; } // ns detail template<typename... xs> -using reverse = typename detail::reverse_<std::tuple<xs...>, std::tuple<>>::type; +using reverse = typename detail::reverse_<detail::tuple<xs...>, detail::tuple<>>::type; -template<template<typename...> class inst, class x> -using lift = typename detail::lift_<inst, x>::type; +// the to/from order is awkward but mimics function composition +template<template<typename...> class to, typename from> +using lift = typename detail::lift_<to, from>::type; template<typename x, typename... xs> using first = x; template<typename x, typename... xs> -using rest = std::tuple<xs...>; +using rest = detail::tuple<xs...>; template<typename... xs> using butlast = reverse<rest<reverse<xs...>>>; @@ -60,9 +69,5 @@ 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 -#endif |