diff options
-rw-r--r-- | src/list/operation/contains.h | 5 | ||||
-rw-r--r-- | src/list/operation/delete.h | 25 | ||||
-rw-r--r-- | test.cc | 25 |
3 files changed, 52 insertions, 3 deletions
diff --git a/src/list/operation/contains.h b/src/list/operation/contains.h index 9e752ed..d3f95fa 100644 --- a/src/list/operation/contains.h +++ b/src/list/operation/contains.h @@ -1,6 +1,7 @@ #ifndef TYPEASVALUE_SRC_LIST_OPERATION_CONTAINS_H_ #define TYPEASVALUE_SRC_LIST_OPERATION_CONTAINS_H_ +#include "type.h" #include "higher/query.h" namespace tav { @@ -12,9 +13,7 @@ template < class Contains { private: template <typename Current> - struct comparator { - typedef std::is_same<Current, Element> type; - }; + using comparator = EqualValue<Current, Element>; public: typedef typename Any<comparator, List>::type type; diff --git a/src/list/operation/delete.h b/src/list/operation/delete.h new file mode 100644 index 0000000..ad0a4cf --- /dev/null +++ b/src/list/operation/delete.h @@ -0,0 +1,25 @@ +#ifndef TYPEASVALUE_SRC_LIST_OPERATION_DELETE_H_ +#define TYPEASVALUE_SRC_LIST_OPERATION_DELETE_H_ + +#include "type.h" +#include "higher/filter.h" + +namespace tav { + +template < + typename Element, + typename List +> +class Delete { + private: + template <typename Current> + using comparator = EqualValue<Current, Element>; + + public: + typedef typename Remove<comparator, List>::type type; + +}; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_DELETE_H_ @@ -17,6 +17,7 @@ #include "list/generator/iota.h" #include "list/generator/make_list.h" #include "list/generator/higher/list_tabulate.h" +#include "list/operation/delete.h" #include "function/apply.h" @@ -434,6 +435,30 @@ static_assert( "(remove even? (list 1 2 3)) != (list 1 3)" ); +// list delete + +static_assert( + std::is_same< + tav::List<tav::Int<1>, tav::Int<3>>::type, + tav::Delete< + tav::Int<2>, + tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type + >::type + >::value, + "(delete 2 (list 1 2 3)) != (list 1 3)" +); + +static_assert( + std::is_same< + tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type, + tav::Delete< + tav::Int<4>, + tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type + >::type + >::value, + "(delete 4 (list 1 2 3)) != (list 1 2 3)" +); + // list partition static_assert( |