diff options
author | Adrian Kummerlaender | 2015-01-22 18:27:20 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2015-01-22 18:27:20 +0100 |
commit | 1d7023c368d68a983faaee4c22fa6700a89393f8 (patch) | |
tree | 810bc1de16ef0484f57b4ead88b3c1e026addd9b | |
parent | 2e58bae3b46dc292736bbdbba6d4ee56b1ee51ed (diff) | |
download | TypeAsValue-1d7023c368d68a983faaee4c22fa6700a89393f8.tar TypeAsValue-1d7023c368d68a983faaee4c22fa6700a89393f8.tar.gz TypeAsValue-1d7023c368d68a983faaee4c22fa6700a89393f8.tar.bz2 TypeAsValue-1d7023c368d68a983faaee4c22fa6700a89393f8.tar.lz TypeAsValue-1d7023c368d68a983faaee4c22fa6700a89393f8.tar.xz TypeAsValue-1d7023c368d68a983faaee4c22fa6700a89393f8.tar.zst TypeAsValue-1d7023c368d68a983faaee4c22fa6700a89393f8.zip |
Implemented Scheme like `Concatenate` in terms of `Fold` and `Append`
* added appropriate test case
-rw-r--r-- | src/list/list.h | 1 | ||||
-rw-r--r-- | src/list/operation/concatenate.h | 18 | ||||
-rw-r--r-- | test.cc | 22 |
3 files changed, 38 insertions, 3 deletions
diff --git a/src/list/list.h b/src/list/list.h index b89e1ca..5c67872 100644 --- a/src/list/list.h +++ b/src/list/list.h @@ -31,5 +31,6 @@ using Tail = Cdr<Cons>; #include "operation/basic.h" #include "operation/append.h" +#include "operation/concatenate.h" #endif // TYPEASVALUE_SRC_LIST_LIST_H_ diff --git a/src/list/operation/concatenate.h b/src/list/operation/concatenate.h new file mode 100644 index 0000000..944470b --- /dev/null +++ b/src/list/operation/concatenate.h @@ -0,0 +1,18 @@ +#ifndef TYPEASVALUE_SRC_LIST_OPERATION_CONCATENATE_H_ +#define TYPEASVALUE_SRC_LIST_OPERATION_CONCATENATE_H_ + +#include "append.h" +#include "higher/fold.h" + +namespace tav { + +template <typename ListOfLists> +using Concatenate = Fold< + Append, + void, + ListOfLists +>; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_CONCATENATE_H_ @@ -317,7 +317,7 @@ static_assert( "(length (take 3 (list 1 2))) != 2" ); -// list concatenate +// list append static_assert( std::is_same< @@ -329,7 +329,7 @@ static_assert( >::type >::type >::value, - "(length (concatenate (list 1) (list 2))) != 2" + "(length (append (list 1) (list 2))) != 2" ); static_assert( @@ -342,7 +342,7 @@ static_assert( >::type >::type >::value, - "(length (concatenate (list 1 2) (list 3 4))) != 4" + "(length (append (list 1 2) (list 3 4))) != 4" ); // list fold @@ -491,3 +491,19 @@ static_assert( >::value, "(contains 0 (list 1 2 3)) != #f" ); + +// list concatenate + +static_assert( + std::is_same< + tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>, tav::Int<4>, tav::Int<5>, tav::Int<6>>::type, + tav::Concatenate< + tav::List< + tav::List<tav::Int<1>, tav::Int<2>>::type, + tav::List<tav::Int<3>>::type, + tav::List<tav::Int<4>, tav::Int<5>, tav::Int<6>>::type + >::type + >::type + >::value, + "(length (concatenate (list (list 1 2) (list 3) (list 4 5 6)))) != 6" +); |