aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-01-18 17:31:20 +0100
committerAdrian Kummerlaender2015-01-18 17:31:20 +0100
commitffe8e376086cddda8bb7ca37b02a48f67cbe513d (patch)
tree7035604330ed0721933dcd0d9f6c25b99658b017
parent7574e3836eec13e6f632b811e6bf001f2e3d2a1d (diff)
downloadTypeAsValue-ffe8e376086cddda8bb7ca37b02a48f67cbe513d.tar
TypeAsValue-ffe8e376086cddda8bb7ca37b02a48f67cbe513d.tar.gz
TypeAsValue-ffe8e376086cddda8bb7ca37b02a48f67cbe513d.tar.bz2
TypeAsValue-ffe8e376086cddda8bb7ca37b02a48f67cbe513d.tar.lz
TypeAsValue-ffe8e376086cddda8bb7ca37b02a48f67cbe513d.tar.xz
TypeAsValue-ffe8e376086cddda8bb7ca37b02a48f67cbe513d.tar.zst
TypeAsValue-ffe8e376086cddda8bb7ca37b02a48f67cbe513d.zip
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
-rw-r--r--src/list/operation/basic.h21
1 files 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 <typename Cons>
-struct Length {
- typedef Add<
- Size<1>,
- typename Length<Tail<Cons>
- >::type> type;
-};
+class Length {
+ private:
+ template <
+ typename,
+ typename Current
+ >
+ struct Count {
+ typedef Add<Size<1>, Current> type;
+ };
-template <>
-struct Length<void> {
- typedef Size<0> type;
+ public:
+ typedef typename Fold<Count, Size<0>, Cons>::type type;
};
template <