From 27b991ea23f71093b274b3ff1692c47274eb4d1d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 26 Jan 2015 19:19:45 +0100 Subject: Redefined `Length` in terms of `Apply` and `Fold` * this function illustrates the use case `Apply` is currently intended for * moved `Take` and `Nth` into separate files to resolve header resolution conflicts --- src/list/operation/basic.h | 72 +++++----------------------------------------- 1 file changed, 7 insertions(+), 65 deletions(-) (limited to 'src/list/operation/basic.h') diff --git a/src/list/operation/basic.h b/src/list/operation/basic.h index d80b347..1f4b043 100644 --- a/src/list/operation/basic.h +++ b/src/list/operation/basic.h @@ -1,76 +1,18 @@ #ifndef TYPEASVALUE_SRC_LIST_OPERATION_BASIC_H_ #define TYPEASVALUE_SRC_LIST_OPERATION_BASIC_H_ -#include "operation/math.h" #include "higher/fold.h" +#include "function/apply.h" +#include "operation/math.h" namespace tav { template -class Length { - private: - template < - typename, - typename Previous - > - struct count { - typedef Add, Previous> type; - }; - - public: - typedef typename Fold, Cons>::type type; - -}; - -template < - typename Index, - typename Cons -> -struct Nth { - typedef typename Nth< - Substract>, - Tail - >::type type; -}; - -template -struct Nth { - typedef void type; -}; - -template -struct Nth, Cons> { - typedef Head 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; -}; +using Length = Fold< + Apply, _1>::pair_type, + Size<0>, + Cons +>; } -- cgit v1.2.3