From 28dd281dd3e7c16185ecdb06b2a83f15bb074717 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 17 Jan 2015 22:45:31 +0100 Subject: Implemented `Take` function * as its name implies this function _takes_ a maximum of _Count_ elements of a list * added appropriate test case --- src/list/operation/basic.h | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/list/operation/basic.h b/src/list/operation/basic.h index cee4cbc..dbd080e 100644 --- a/src/list/operation/basic.h +++ b/src/list/operation/basic.h @@ -2,6 +2,7 @@ #define TYPEASVALUE_SRC_LIST_OPERATION_BASIC_H_ #include "operation/math.h" +#include "conditional/if.h" namespace tav { @@ -26,7 +27,10 @@ struct Nth { typedef If< equal_value>::value, Head, - typename Nth>, Tail>::type + typename Nth< + Substract>, + Tail + >::type > type; }; @@ -35,6 +39,35 @@ struct Nth { typedef void type; }; +template < + typename Count, + typename Current +> +struct Take { + typedef Cons< + Head, + typename Take< + Substract>, + Tail + >::type + > type; +}; + +template +struct Take, Current> { + typedef void type; +}; + +template +struct Take { + typedef void type; +}; + +template <> +struct Take, void> { + typedef void type; +}; + } #endif // TYPEASVALUE_SRC_LIST_OPERATION_BASIC_H_ -- cgit v1.2.3