• 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

修订版72ab932b7505d9087087d8b9fbed62414705bbfb (tree)
时间2017-03-22 12:52:59
作者Yamashta Daisuke <yamasdais@gmai...>
CommiterYamashta Daisuke

Log Message

added apply<T...>
improved is_cons<T> check

更改概述

差异

--- a/cxx/fmp.cc
+++ b/cxx/fmp.cc
@@ -69,6 +69,15 @@ struct any<cons<A, D>> {
6969 using value_type = cons<A, D>;
7070 };
7171
72+template <typename T>
73+std::false_type check_cons(...);
74+
75+template <typename T>
76+auto check_cons(T*) -> decltype(
77+ std::is_same<typename T::car_type, typename T::cdr_type>::value,
78+ std::true_type()
79+);
80+
7281 } // detail
7382
7483 using nil = detail::nil_type;
@@ -99,11 +108,16 @@ struct is_nil : public std::false_type { };
99108 template <>
100109 struct is_nil<nil> : public std::true_type { };
101110
111+#if 0
102112 template <typename T>
103113 struct is_cons : public std::false_type { };
104114
105115 template <typename T0, typename T1>
106116 struct is_cons<cons<T0, T1>> : std::true_type { };
117+#endif
118+template <typename T>
119+struct is_cons : public decltype(detail::check_cons<T>(nullptr)) {
120+};
107121
108122 template <typename T>
109123 struct is_atom : public std::true_type { };
@@ -169,6 +183,12 @@ struct list {
169183 using apply = typename detail::list_elem<T...>::apply;
170184 };
171185
186+template <template <class...> typename F,
187+ typename... Rest>
188+struct apply {
189+ using type = typename F<Rest...>::apply;
190+};
191+
172192 template <typename Cond, typename IfTrue, typename IfFalse = nil>
173193 struct if_t {
174194 using apply = typename std::conditional<
@@ -180,8 +200,10 @@ struct if_t {
180200
181201 void test_list() {
182202 using namespace fmp;
183- using l_0 = list<>::apply; // (list) => nil
184- using l_int = list<int>::apply; // (list 'int) => (INT)
203+ //using l_0 = list<>::apply; // (list) => nil
204+ using l_0 = apply<list>::type;
205+ //using l_int = list<int>::apply; // (list 'int) => (INT)
206+ using l_int = apply<list, int>::type;
185207 using l_2 = list<int, char>::apply;
186208 using l_3 = list<int, char, float>::apply;
187209 using l_4 = list<int, char, float, double>::apply;
@@ -241,6 +263,7 @@ void test0() {
241263
242264 static_assert(eq<int1::value_type, int>::value, "int1 == int");
243265 static_assert(int1::value == 1, "val<int, 1> == 1");
266+ static_assert(!is_cons<nil>::value, "is_cons<nil> != true");
244267 static_assert(!fmp::is_cons<int>::value, "is_cons<int> != true");
245268 static_assert(fmp::is_cons<cint>::value, "is_consp<cint> == true");
246269 static_assert(fmp::is_nil<fmp::cons<fmp::nil>::car::value_type>::value,