From ffe8e376086cddda8bb7ca37b02a48f67cbe513d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 18 Jan 2015 17:31:20 +0100 Subject: Reimplemented `Length` function in terms of `Fold` * this removes the need for maintaining a partial overload of `Length` * the recursive traversion of the _Cons_ structure is now implemented by `Fold` instead of needlessly duplicating it --- src/list/operation/basic.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/list/operation/basic.h b/src/list/operation/basic.h index 586cf2f..ff0a4d7 100644 --- a/src/list/operation/basic.h +++ b/src/list/operation/basic.h @@ -2,20 +2,23 @@ #define TYPEASVALUE_SRC_LIST_OPERATION_BASIC_H_ #include "operation/math.h" +#include "higher/fold.h" namespace tav { template -struct Length { - typedef Add< - Size<1>, - typename Length - >::type> type; -}; +class Length { + private: + template < + typename, + typename Current + > + struct Count { + typedef Add, Current> type; + }; -template <> -struct Length { - typedef Size<0> type; + public: + typedef typename Fold, Cons>::type type; }; template < -- cgit v1.2.3