aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/list/operation/higher/misc.h20
-rw-r--r--test.cc5
2 files changed, 25 insertions, 0 deletions
diff --git a/src/list/operation/higher/misc.h b/src/list/operation/higher/misc.h
index 708265a..280c0d5 100644
--- a/src/list/operation/higher/misc.h
+++ b/src/list/operation/higher/misc.h
@@ -2,6 +2,7 @@
#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_MISC_H_
#include "fold.h"
+#include "list/operation/concatenate.h"
namespace tav {
@@ -24,6 +25,25 @@ class Map {
};
+template <typename List>
+class Reverse {
+ private:
+ template <
+ typename Current,
+ typename Previous
+ >
+ struct ReversedConcatenate {
+ typedef typename Concatenate<
+ Previous,
+ Cons<Current, void>
+ >::type type;
+ };
+
+ public:
+ typedef typename Fold<ReversedConcatenate, void, List>::type type;
+
+};
+
}
#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_MISC_H_
diff --git a/test.cc b/test.cc
index 6b9dffb..655aed3 100644
--- a/test.cc
+++ b/test.cc
@@ -99,6 +99,11 @@ TEST_F(TypeAsValueTest, ListMap) {
EXPECT_TRUE(( std::is_same<tav::List<tav::Int<4>, tav::Int<8>, tav::Int<12>>::type, tav::Map<quadruple, tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>::type>::value ));
}
+TEST_F(TypeAsValueTest, ListReverse) {
+ // (reverse (list 1 2 3))
+ EXPECT_TRUE(( std::is_same<tav::List<tav::Int<3>, tav::Int<2>, tav::Int<1>>::type, tav::Reverse<tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>::type>::value ));
+}
+
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);