aboutsummaryrefslogtreecommitdiff
path: root/src/list/operation/section.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/list/operation/section.h')
-rw-r--r--src/list/operation/section.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/list/operation/section.h b/src/list/operation/section.h
new file mode 100644
index 0000000..214c9fd
--- /dev/null
+++ b/src/list/operation/section.h
@@ -0,0 +1,76 @@
+#ifndef TYPEASVALUE_SRC_LIST_OPERATION_SECTION_H_
+#define TYPEASVALUE_SRC_LIST_OPERATION_SECTION_H_
+
+#include "operation/math.h"
+
+namespace tav {
+
+namespace detail {
+
+template <
+ typename Index,
+ typename Count,
+ typename List
+>
+struct take_count_at {
+ typedef Eval<take_count_at<
+ Substract<Index, Size<1>>,
+ Count,
+ Tail<List>
+ >> type;
+};
+
+template <
+ typename Count,
+ typename List
+>
+struct take_count_at<Size<0>, Count, List> {
+ typedef Cons<
+ Head<List>,
+ Eval<take_count_at<
+ Size<0>,
+ Substract<Count, Size<1>>,
+ Tail<List>
+ >>
+ > type;
+};
+
+template <
+ typename Index,
+ typename Count
+>
+struct take_count_at<Index, Count, void> {
+ typedef void type;
+};
+
+template <typename Count>
+struct take_count_at<Size<0>, Count, void> {
+ typedef void type;
+};
+
+template <typename List>
+struct take_count_at<Size<0>, Size<0>, List> {
+ typedef void type;
+};
+
+template <>
+struct take_count_at<Size<0>, Size<0>, void> {
+ typedef void type;
+};
+
+}
+
+template <
+ typename Start,
+ typename End,
+ typename List
+>
+using Section = Eval<detail::take_count_at<
+ Start,
+ Substract<Add<End, Size<1>>, Start>,
+ List
+>>;
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_OPERATION_SECTION_H_