• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

test, trial, experiments


Commit MetaInfo

修订版b28b114202f3ac0f4b35e2df52e8189ff0159491 (tree)
时间2017-03-23 13:00:57
作者Yamashta Daisuke <yamasdais@gmai...>
CommiterYamashta Daisuke

Log Message

[refactor] conditional meta classes.
[add] t_type
[add] and, or

更改概述

差异

--- a/cxx/fmp.cc
+++ b/cxx/fmp.cc
@@ -48,19 +48,26 @@ struct chary {
4848 constexpr static T ary[size] = { V..., static_cast<T>(0) };
4949 };
5050
51+struct t_type : public std::true_type {
52+};
53+
5154 struct nil_type : public std::false_type {
5255 };
5356
54-#if 0
55-template <typename T>
56-std::false_type check_cons(...);
57+template <template <class> typename F, typename V>
58+class pred_elem {
59+ using apply = typename F<V>::apply;
60+};
5761
58-template <typename T>
59-auto check_cons(T*) -> decltype(
60- std::is_same<typename T::car_type, typename T::cdr_type>::value,
61- std::true_type()
62-);
63-#endif
62+template <template <class> typename F, typename V>
63+constexpr static auto pred_elem_v = pred_elem<F, V>::apply::value;
64+
65+template <template <class> typename F>
66+class and_impl {
67+};
68+
69+class or_impl {
70+};
6471
6572 class is_cons_impl {
6673 template <typename T>
@@ -69,27 +76,41 @@ class is_cons_impl {
6976 template <typename T>
7077 static auto check(T*) -> decltype(
7178 std::is_same<typename T::car_type, typename T::cdr_type>::value,
72- std::true_type()
79+ t_type()
7380 );
7481 public:
7582 template <typename T>
76- using pred = decltype(check<T>(nullptr));
83+ using apply = decltype(check<T>(nullptr));
7784 };
7885
7986 class is_atom_impl {
8087 template <typename T>
81- static std::true_type check(...);
88+ static t_type check(...);
8289
8390 template <typename T>
8491 static auto check(T*)-> decltype(
85- //std::is_same<typename T::car_type, typename T::cdr_type>::value,
86- is_cons_impl::pred<T>::value,
92+ std::is_same<typename T::car_type, typename T::cdr_type>::value,
8793 nil_type()
8894 );
8995
9096 public:
9197 template <typename T>
92- using pred = decltype(check<T>(nullptr));
98+ using apply = decltype(check<T>(nullptr));
99+};
100+
101+struct is_t_impl {
102+ template <typename T>
103+ using apply = typename std::conditional<
104+ std::is_base_of<std::false_type, T>::value,
105+ nil_type, t_type>::type;
106+};
107+
108+
109+struct is_nil_impl {
110+ template <typename T>
111+ using apply = typename std::conditional<
112+ std::is_base_of<std::false_type, T>::value,
113+ t_type, nil_type>::type;
93114 };
94115
95116 } // detail
@@ -107,42 +128,30 @@ struct cons {
107128 using cdr = detail::any<D>;
108129 };
109130
110-
111-template <typename T>
112-struct is_t : public std::true_type { };
113-
114-template <>
115-struct is_t<nil> : public nil { };
116-
117131 template <typename T>
118-struct is_nil : public nil { };
119-
120-template <>
121-struct is_nil<nil> : public std::true_type { };
132+struct is_t : public detail::is_t_impl::apply<T> {
133+};
122134
123135 template <typename T>
124-struct is_cons : public detail::is_cons_impl::pred<T> {
136+struct is_nil : public detail::is_nil_impl::apply<T> {
125137 };
126138
127-#if 0
128139 template <typename T>
129-struct is_atom : public std::true_type { };
140+struct is_cons : public detail::is_cons_impl::apply<T> {
141+};
130142
131-template <typename T0, typename T1>
132-struct is_atom<cons<T0, T1>> : std::false_type { };
133-#endif
134143 template <typename T>
135-struct is_atom : public detail::is_atom_impl::pred<T> {
144+struct is_atom : public detail::is_atom_impl::apply<T> {
136145 };
137146
138147 template <typename T>
139148 struct is_list : public nil { };
140149
141150 template <>
142-struct is_list<nil> : public std::true_type { };
151+struct is_list<nil> : public detail::t_type { };
143152
144153 template <typename T0, typename T1>
145-struct is_list<cons<T0, T1>> : public std::true_type { };
154+struct is_list<cons<T0, T1>> : public detail::t_type { };
146155
147156 namespace detail {
148157
@@ -162,6 +171,12 @@ struct list_elem<> {
162171 }
163172
164173 template <typename T>
174+struct quote {
175+ using type = quote<T>;
176+ using apply = T;
177+};
178+
179+template <typename T>
165180 struct car {
166181 using apply = typename T::car_type;
167182 };
@@ -185,7 +200,7 @@ template <typename, typename>
185200 struct eq : public nil { };
186201
187202 template <typename T>
188-struct eq<T, T> : public std::true_type { };
203+struct eq<T, T> : public detail::t_type { };
189204
190205 template <typename ...T>
191206 struct list {
@@ -273,8 +288,7 @@ void test_atom() {
273288 static_assert(is_t<is_atom<int>>::value, "is_atom<int> == t");
274289 static_assert(is_t<is_atom<nil>>::value, "is_atom<nil> == t");
275290 static_assert(!is_atom<cons<int>>::value, "is_atom<cons<int>> == nil");
276-
277- is_atom<cons<int>>::type foo;
291+ static_assert(is_nil<is_atom<cons<int>>>::value, "foo == nil");
278292 }
279293
280294 void test0() {