From a9ec2e4e13670c8084c6baae59d6f3631960e22c Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 31 Jan 2015 12:04:34 +0100 Subject: Implemented higher order `Find` list search operation * added appropriate test case * other queries in `query.h` may be redefined in terms of `Find` --- src/list/operation/higher/find.h | 30 ++++++++++++++++++++++++++++++ src/list/operation/higher/query.h | 16 ++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 src/list/operation/higher/find.h (limited to 'src/list') diff --git a/src/list/operation/higher/find.h b/src/list/operation/higher/find.h new file mode 100644 index 0000000..47b88ad --- /dev/null +++ b/src/list/operation/higher/find.h @@ -0,0 +1,30 @@ +#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FIND_H_ +#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FIND_H_ + +#include "type.h" +#include "conditional/if.h" + +namespace tav { + +template < + template class Predicate, + typename Current +> +struct Find { + typedef If< + Predicate>::type::value, + Head, + typename Find>::type + > type; +}; + +template < + template class Predicate +> +struct Find { + typedef Boolean type; +}; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FIND_H_ diff --git a/src/list/operation/higher/query.h b/src/list/operation/higher/query.h index 198ffa5..d2b8e76 100644 --- a/src/list/operation/higher/query.h +++ b/src/list/operation/higher/query.h @@ -9,41 +9,41 @@ namespace tav { template < - template class Function, + template class Predicate, typename List > using Any = Fold< Or, Boolean, - typename Map::type + typename Map::type >; template < - template class Function, + template class Predicate, typename List > using All = Fold< And, Boolean, - typename Map::type + typename Map::type >; template < - template class Function, + template class Predicate, typename List > using None = Not< - typename Any::type + typename Any::type >; template < - template class Function, + template class Predicate, typename List > using Count = Fold< Add, tav::Size<0>, - typename Map::type + typename Map::type >; } -- cgit v1.2.3