From 8e4e3466694e5bef43f1308296a76086a7db453d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 17 Feb 2015 18:55:08 +0100 Subject: 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 --- src/list/operation/section.h | 76 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/list/operation/section.h (limited to 'src/list/operation/section.h') 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>, + Count, + Tail + >> type; +}; + +template < + typename Count, + typename List +> +struct take_count_at, Count, List> { + typedef Cons< + Head, + Eval, + Substract>, + Tail + >> + > type; +}; + +template < + typename Index, + typename Count +> +struct take_count_at { + typedef void type; +}; + +template +struct take_count_at, Count, void> { + typedef void type; +}; + +template +struct take_count_at, Size<0>, List> { + typedef void type; +}; + +template <> +struct take_count_at, Size<0>, void> { + typedef void type; +}; + +} + +template < + typename Start, + typename End, + typename List +> +using Section = Eval>, Start>, + List +>>; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_SECTION_H_ -- cgit v1.2.3