diff options
author | Adrian Kummerlaender | 2015-02-10 18:40:05 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2015-02-10 18:40:05 +0100 |
commit | f1268ca3bf10ab136bafbd63894ce12353fa8690 (patch) | |
tree | 047add598bc7ac82de9931ebd9b0780cf2dfbbb4 | |
parent | 8893f72598040681aec3de58740212c0003fc65b (diff) | |
download | TypeAsValue-f1268ca3bf10ab136bafbd63894ce12353fa8690.tar TypeAsValue-f1268ca3bf10ab136bafbd63894ce12353fa8690.tar.gz TypeAsValue-f1268ca3bf10ab136bafbd63894ce12353fa8690.tar.bz2 TypeAsValue-f1268ca3bf10ab136bafbd63894ce12353fa8690.tar.lz TypeAsValue-f1268ca3bf10ab136bafbd63894ce12353fa8690.tar.xz TypeAsValue-f1268ca3bf10ab136bafbd63894ce12353fa8690.tar.zst TypeAsValue-f1268ca3bf10ab136bafbd63894ce12353fa8690.zip |
Moved `Sort` list index deletion into `DeleteNth` function
* as it is commonly required functionality and as such should be provided by this library
-rw-r--r-- | src/list/operation/delete_nth.h | 21 | ||||
-rw-r--r-- | src/list/operation/higher/sort.h | 8 | ||||
-rw-r--r-- | test.cc | 14 |
3 files changed, 37 insertions, 6 deletions
diff --git a/src/list/operation/delete_nth.h b/src/list/operation/delete_nth.h new file mode 100644 index 0000000..03df12a --- /dev/null +++ b/src/list/operation/delete_nth.h @@ -0,0 +1,21 @@ +#ifndef TYPEASVALUE_SRC_LIST_OPERATION_DELETE_NTH_H_ +#define TYPEASVALUE_SRC_LIST_OPERATION_DELETE_NTH_H_ + +#include "list/operation/append.h" +#include "list/operation/take.h" +#include "list/operation/drop.h" + +namespace tav { + +template < + typename Index, + typename List +> +using DeleteNth = Append< + typename Take<Index, List>::type, + typename Drop<Add<Index, Size<1>>, List>::type +>; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_DELETE_NTH_H_ diff --git a/src/list/operation/higher/sort.h b/src/list/operation/higher/sort.h index a707a15..f9146d6 100644 --- a/src/list/operation/higher/sort.h +++ b/src/list/operation/higher/sort.h @@ -2,6 +2,7 @@ #define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_SORT_H_ #include "list/operation/concatenate.h" +#include "list/operation/delete_nth.h" #include "list/operation/higher/partition.h" #include "function/apply.h" @@ -16,14 +17,9 @@ class Sort { using index = Divide<typename Length<Sequence>::type, Size<2>>; using pivot = typename Nth<index, Sequence>::type; - using sequence_sans_pivot = typename Append< - typename Take<index, Sequence>::type, - typename Drop<Add<index, Size<1>>, Sequence>::type - >::type; - using partitions = typename Partition< Apply<Comparator, pivot, tav::_0>::template single_type, - sequence_sans_pivot + typename DeleteNth<index, Sequence>::type >::type; using lhs = typename Car<partitions>::type; @@ -19,6 +19,7 @@ #include "list/generator/make_list.h" #include "list/generator/higher/list_tabulate.h" #include "list/operation/delete.h" +#include "list/operation/delete_nth.h" #include "function/apply.h" @@ -595,6 +596,19 @@ static_assert( "(delete 4 (list 1 2 3)) != (list 1 2 3)" ); +// list delete nth + +static_assert( + std::is_same< + tav::List<tav::Int<1>, tav::Int<3>>::type, + tav::DeleteNth< + tav::Size<1>, + tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type + >::type + >::value, + "(delete-nth 1 (list 1 2 3)) != (list 1 3)" +); + // list partition static_assert( |