summaryrefslogtreecommitdiffhomepage
path: root/compat/meta.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-07-14 08:59:16 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-07-14 09:09:14 +0200
commita924f54ef87764bd9bc257babd3a02aafcc90cbb (patch)
tree34e90ad073b220fa357210f90b478593514b27c7 /compat/meta.hpp
parent88103dd3dd5a8bdd70958eea9eac65973941aa87 (diff)
compat/meta: fixes
Diffstat (limited to 'compat/meta.hpp')
-rw-r--r--compat/meta.hpp71
1 files changed, 54 insertions, 17 deletions
diff --git a/compat/meta.hpp b/compat/meta.hpp
index a116cebc..4dec8bbb 100644
--- a/compat/meta.hpp
+++ b/compat/meta.hpp
@@ -7,20 +7,13 @@
* copyright notice and this permission notice appear in all copies.
*/
-#define OTR_META_INST_FAIL(x) \
- static_assert(sizeof...(x) == ~0ul); \
- static_assert(sizeof...(x) == 0u)
-
namespace meta::detail {
template<typename... xs>
struct tuple;
template<typename... xs>
- struct reverse_
- {
- OTR_META_INST_FAIL(xs);
- };
+ struct reverse_;
template<typename x0, typename... xs, template<typename...> class x, typename... ys>
struct reverse_<x<x0, xs...>, x<ys...>>
@@ -34,11 +27,7 @@ namespace meta::detail {
using type = x<ys...>;
};
- template<template<typename...> class inst, typename... xs>
- struct lift_
- {
- OTR_META_INST_FAIL(xs);
- };
+ template<template<typename...> class, typename, typename...> struct lift_;
template<template<typename...> class to, template<typename...> class from, typename... xs>
struct lift_<to, from<xs...>>
@@ -46,18 +35,60 @@ namespace meta::detail {
using type = to<xs...>;
};
- template<typename...> struct cons_;
+ template<typename> struct append_helper;
+
+ template<typename, typename> struct cons_;
template<template<typename...> class t, typename x, typename... xs>
- struct cons_<t<xs...>, x>
+ struct cons_<x, t<xs...>>
{
using type = t<x, xs...>;
};
+ template<typename> struct append2;
+
+ template<template<typename...> class t, typename... xs>
+ struct append2<t<xs...>>
+ {
+ template<typename> struct append1;
+
+ template<template<typename...> class u, typename... ys>
+ struct append1<u<ys...>>
+ {
+ using type = t<xs..., ys...>;
+ };
+ };
+
+ template<typename, typename...> struct list__;
+
+ template<typename rest, typename... first>
+ struct list__
+ {
+ template<typename> struct list1;
+
+ template<template<typename...> class t, typename... xs>
+ struct list1<t<xs...>>
+ {
+ using type = t<first..., xs...>;
+ };
+
+ using type = typename list1<rest>::type;
+ };
+
+ template<typename xs, typename ys>
+ struct append_
+ {
+ using t1 = append2<xs>;
+ using type = typename t1::template append1<ys>::type;
+ };
+
} // ns meta::detail
namespace meta {
template<typename... xs>
+ using tuple_ = detail::tuple<xs...>;
+
+ template<typename... xs>
using reverse = typename detail::reverse_<detail::tuple<xs...>, detail::tuple<>>::type;
// the to/from order is awkward but mimics function composition
@@ -76,8 +107,14 @@ namespace meta {
template<typename... xs>
using last = lift<first, reverse<xs...>>;
- template<typename... xs>
- using cons = detail::cons_<xs...>;
+ template<typename x, typename rest>
+ using cons = typename detail::cons_<x, rest>::type;
+
+ template<typename xs, typename ys>
+ using append = typename detail::append_<xs, ys>;
+
+ template<typename rest, typename... xs>
+ using list_ = typename detail::list__<rest, xs...>;
} // ns meta