From 8432906bf9be6f16aafdb23aaed34f1247404329 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Fri, 23 Jan 2015 20:32:48 +0100 Subject: Implemented `ListTabulate` in terms of `Iota` and `Map` * added `Square` function to math operations header to facilitate a simple test case * added appropriate test case --- src/list/generator/higher/list_tabulate.h | 20 ++++++++++++++++++ src/list/generator/iota.h | 34 +++++++++++++++++++++++++++++++ src/list/iota.h | 34 ------------------------------- src/operation/math.h | 3 +++ 4 files changed, 57 insertions(+), 34 deletions(-) create mode 100644 src/list/generator/higher/list_tabulate.h create mode 100644 src/list/generator/iota.h delete mode 100644 src/list/iota.h (limited to 'src') diff --git a/src/list/generator/higher/list_tabulate.h b/src/list/generator/higher/list_tabulate.h new file mode 100644 index 0000000..9eee599 --- /dev/null +++ b/src/list/generator/higher/list_tabulate.h @@ -0,0 +1,20 @@ +#ifndef TYPEASVALUE_SRC_LIST_GENERATOR_HIGHER_LIST_TABULATE_H_ +#define TYPEASVALUE_SRC_LIST_GENERATOR_HIGHER_LIST_TABULATE_H_ + +#include "list/generator/iota.h" +#include "list/operation/higher/misc.h" + +namespace tav { + +template < + typename Count, + template class Initializer +> +using ListTabulate = Map< + Initializer, + typename Iota, Size<1>>::type +>; + +} + +#endif // TYPEASVALUE_SRC_LIST_GENERATOR_HIGHER_LIST_TABULATE_H_ diff --git a/src/list/generator/iota.h b/src/list/generator/iota.h new file mode 100644 index 0000000..54f0f40 --- /dev/null +++ b/src/list/generator/iota.h @@ -0,0 +1,34 @@ +#ifndef TYPEASVALUE_SRC_LIST_GENERATOR_IOTA_H_ +#define TYPEASVALUE_SRC_LIST_GENERATOR_IOTA_H_ + +#include "operation/math.h" + +namespace tav { + +template < + typename Count, + typename Initial, + typename Step +> +struct Iota { + typedef Cons< + Initial, + typename Iota< + Substract>, + Add, + Step + >::type + > type; +}; + +template < + typename Initial, + typename Step +> +struct Iota, Initial, Step> { + typedef Cons type; +}; + +} + +#endif // TYPEASVALUE_SRC_LIST_GENERATOR_IOTA_H_ diff --git a/src/list/iota.h b/src/list/iota.h deleted file mode 100644 index 9a8d22d..0000000 --- a/src/list/iota.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TYPEASVALUE_SRC_LIST_IOTA_H_ -#define TYPEASVALUE_SRC_LIST_IOTA_H_ - -#include "operation/math.h" - -namespace tav { - -template < - typename Count, - typename Initial, - typename Step -> -struct Iota { - typedef Cons< - Initial, - typename Iota< - Substract>, - Add, - Step - >::type - > type; -}; - -template < - typename Initial, - typename Step -> -struct Iota, Initial, Step> { - typedef Cons type; -}; - -} - -#endif // TYPEASVALUE_SRC_LIST_IOTA_H_ diff --git a/src/operation/math.h b/src/operation/math.h index b06eb35..0ede3f5 100644 --- a/src/operation/math.h +++ b/src/operation/math.h @@ -41,6 +41,9 @@ using Divide = typename std::integral_constant< X::value / Y::value >::type; +template +using Square = Multiply; + template using Even = Boolean<(X::value % 2 == 0)>; -- cgit v1.2.3