diff options
author | Adrian Kummerlaender | 2015-01-26 19:19:45 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2015-01-26 19:19:45 +0100 |
commit | 27b991ea23f71093b274b3ff1692c47274eb4d1d (patch) | |
tree | 10c4d4243087441484d57dddd3cefcd3888152f9 /src/list/operation/basic.h | |
parent | 7ce93ff513a993b8b46fbb401b232d6f557b948b (diff) | |
download | TypeAsValue-27b991ea23f71093b274b3ff1692c47274eb4d1d.tar TypeAsValue-27b991ea23f71093b274b3ff1692c47274eb4d1d.tar.gz TypeAsValue-27b991ea23f71093b274b3ff1692c47274eb4d1d.tar.bz2 TypeAsValue-27b991ea23f71093b274b3ff1692c47274eb4d1d.tar.lz TypeAsValue-27b991ea23f71093b274b3ff1692c47274eb4d1d.tar.xz TypeAsValue-27b991ea23f71093b274b3ff1692c47274eb4d1d.tar.zst TypeAsValue-27b991ea23f71093b274b3ff1692c47274eb4d1d.zip |
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
Diffstat (limited to 'src/list/operation/basic.h')
-rw-r--r-- | src/list/operation/basic.h | 72 |
1 files changed, 7 insertions, 65 deletions
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 <typename Cons> -class Length { - private: - template < - typename, - typename Previous - > - struct count { - typedef Add<Size<1>, Previous> type; - }; - - public: - typedef typename Fold<count, Size<0>, Cons>::type type; - -}; - -template < - typename Index, - typename Cons -> -struct Nth { - typedef typename Nth< - Substract<Index, Size<1>>, - Tail<Cons> - >::type type; -}; - -template <typename Index> -struct Nth<Index, void> { - typedef void type; -}; - -template <typename Cons> -struct Nth<Size<0>, Cons> { - typedef Head<Cons> type; -}; - -template < - typename Count, - typename Current -> -struct Take { - typedef Cons< - Head<Current>, - typename Take< - Substract<Count, Size<1>>, - Tail<Current> - >::type - > type; -}; - -template <typename Current> -struct Take<Size<0>, Current> { - typedef void type; -}; - -template <typename Count> -struct Take<Count, void> { - typedef void type; -}; - -template <> -struct Take<Size<0>, void> { - typedef void type; -}; +using Length = Fold< + Apply<Add, Size<1>, _1>::pair_type, + Size<0>, + Cons +>; } |