aboutsummaryrefslogtreecommitdiff
path: root/src/list/operation/length.h
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-17 18:55:08 +0100
committerAdrian Kummerlaender2015-02-17 18:55:08 +0100
commit8e4e3466694e5bef43f1308296a76086a7db453d (patch)
tree84049e2604341a0326e99d31cbed898fe5448d2d /src/list/operation/length.h
parentf81cd736e00c28cf24412a4099bae08ff2e6c493 (diff)
downloadTypeAsValue-8e4e3466694e5bef43f1308296a76086a7db453d.tar
TypeAsValue-8e4e3466694e5bef43f1308296a76086a7db453d.tar.gz
TypeAsValue-8e4e3466694e5bef43f1308296a76086a7db453d.tar.bz2
TypeAsValue-8e4e3466694e5bef43f1308296a76086a7db453d.tar.lz
TypeAsValue-8e4e3466694e5bef43f1308296a76086a7db453d.tar.xz
TypeAsValue-8e4e3466694e5bef43f1308296a76086a7db453d.tar.zst
TypeAsValue-8e4e3466694e5bef43f1308296a76086a7db453d.zip
Expressed `Take` and `Drop` in terms of new `Section` operation
* unifies the common functionality between `Take` and `Drop` * renamed `basic.h` to `length.h` as it only contains the `Length` implementation
Diffstat (limited to 'src/list/operation/length.h')
-rw-r--r--src/list/operation/length.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/list/operation/length.h b/src/list/operation/length.h
new file mode 100644
index 0000000..1f609d4
--- /dev/null
+++ b/src/list/operation/length.h
@@ -0,0 +1,21 @@
+#ifndef TYPEASVALUE_SRC_LIST_OPERATION_LENGTH_H_
+#define TYPEASVALUE_SRC_LIST_OPERATION_LENGTH_H_
+
+#include "higher/fold.h"
+#include "operation/math.h"
+
+namespace tav {
+
+namespace detail {
+
+template <typename, typename Accumulated>
+using length_accumulate = Add<Size<1>, Accumulated>;
+
+}
+
+template <typename List>
+using Length = Fold<detail::length_accumulate, Size<0>, List>;
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_OPERATION_LENGTH_H_