From 8418b810998276f1aa9556f7df2d5270a9600d94 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Mon, 18 Aug 2014 20:21:32 +0900 Subject: [PATCH] add comparison and arithmetic type functionals --- sprout/type.hpp | 1 + sprout/type/algorithm/fold.hpp | 6 +-- sprout/type/functional.hpp | 4 +- sprout/type/functional/arithmetic.hpp | 18 +++++++ sprout/type/functional/comparison.hpp | 18 +++++++ .../type/functional/detail/arithmetic_op.hpp | 50 +++++++++++++++++++ .../type/functional/detail/comparison_op.hpp | 36 +++++++++++++ sprout/type/functional/divides.hpp | 16 ++++++ sprout/type/functional/equal_to.hpp | 16 ++++++ sprout/type/functional/greater.hpp | 16 ++++++ sprout/type/functional/greater_equal.hpp | 16 ++++++ sprout/type/functional/less.hpp | 30 +---------- sprout/type/functional/less_equal.hpp | 16 ++++++ sprout/type/functional/minus.hpp | 16 ++++++ sprout/type/functional/modulus.hpp | 16 ++++++ sprout/type/functional/multiplies.hpp | 16 ++++++ sprout/type/functional/not_equal_to.hpp | 16 ++++++ sprout/type/functional/plus.hpp | 44 +--------------- sprout/type/self.hpp | 35 +++++++++++++ 19 files changed, 311 insertions(+), 75 deletions(-) create mode 100644 sprout/type/functional/arithmetic.hpp create mode 100644 sprout/type/functional/comparison.hpp create mode 100644 sprout/type/functional/detail/arithmetic_op.hpp create mode 100644 sprout/type/functional/detail/comparison_op.hpp create mode 100644 sprout/type/functional/divides.hpp create mode 100644 sprout/type/functional/equal_to.hpp create mode 100644 sprout/type/functional/greater.hpp create mode 100644 sprout/type/functional/greater_equal.hpp create mode 100644 sprout/type/functional/less_equal.hpp create mode 100644 sprout/type/functional/minus.hpp create mode 100644 sprout/type/functional/modulus.hpp create mode 100644 sprout/type/functional/multiplies.hpp create mode 100644 sprout/type/functional/not_equal_to.hpp create mode 100644 sprout/type/self.hpp diff --git a/sprout/type.hpp b/sprout/type.hpp index f95eca7e..1ea86eb1 100644 --- a/sprout/type.hpp +++ b/sprout/type.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/sprout/type/algorithm/fold.hpp b/sprout/type/algorithm/fold.hpp index 380df5a2..f82a25b0 100644 --- a/sprout/type/algorithm/fold.hpp +++ b/sprout/type/algorithm/fold.hpp @@ -19,15 +19,15 @@ namespace sprout { namespace detail { template< typename Tuple, typename T, typename BinaryOp, std::size_t I, - bool = (I == sprout::types::tuple_size::value) + bool Valid = (I != sprout::types::tuple_size::value) > struct fold_impl; template - struct fold_impl + struct fold_impl : public sprout::identity {}; template - struct fold_impl + struct fold_impl : public sprout::types::detail::fold_impl< Tuple, typename sprout::types::apply::type>::type, diff --git a/sprout/type/functional.hpp b/sprout/type/functional.hpp index 50c2ba4f..b0969f01 100644 --- a/sprout/type/functional.hpp +++ b/sprout/type/functional.hpp @@ -9,7 +9,7 @@ #define SPROUT_TYPE_FUNCTIONAL_HPP #include -#include -#include +#include +#include #endif // #ifndef SPROUT_TYPE_FUNCTIONAL_HPP diff --git a/sprout/type/functional/arithmetic.hpp b/sprout/type/functional/arithmetic.hpp new file mode 100644 index 00000000..7fd14386 --- /dev/null +++ b/sprout/type/functional/arithmetic.hpp @@ -0,0 +1,18 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_ARITHMETIC_HPP +#define SPROUT_TYPE_FUNCTIONAL_ARITHMETIC_HPP + +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_ARITHMETIC_HPP diff --git a/sprout/type/functional/comparison.hpp b/sprout/type/functional/comparison.hpp new file mode 100644 index 00000000..0f8779fe --- /dev/null +++ b/sprout/type/functional/comparison.hpp @@ -0,0 +1,18 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_COMPARISON_HPP +#define SPROUT_TYPE_FUNCTIONAL_COMPARISON_HPP + +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_COMPARISON_HPP diff --git a/sprout/type/functional/detail/arithmetic_op.hpp b/sprout/type/functional/detail/arithmetic_op.hpp new file mode 100644 index 00000000..56990eed --- /dev/null +++ b/sprout/type/functional/detail/arithmetic_op.hpp @@ -0,0 +1,50 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_DETAIL_ARITHMETIC_OP_HPP +#define SPROUT_TYPE_FUNCTIONAL_DETAIL_ARITHMETIC_OP_HPP + +#include +#include +#include +#include + +#define SPROUT_TYPES_DETAIL_FUNCTIONAL_ARITHMETIC_BINARY_OP_DECL(NAME, OP) \ +namespace sprout { \ + namespace types { \ + template \ + struct NAME \ + : public sprout::integral_constant \ + {}; \ + template \ + struct NAME \ + : public sprout::integral_constant< \ + typename sprout::arithmetic_promote::type, \ + (T::value OP U::value) \ + > \ + {}; \ + template \ + struct SPROUT_PP_CAT(NAME, _mf) { \ + public: \ + template \ + struct apply \ + : public sprout::types::NAME \ + {}; \ + }; \ + typedef sprout::types::SPROUT_PP_CAT(NAME, _mf)<> SPROUT_PP_CAT(NAME, _); \ + SPROUT_TYPES_DETAIL_FUNCTIONAL_ARITHMETIC_BINARY_OP_VT_DECL(NAME) \ + } \ +} +#if SPROUT_USE_VARIABLE_TEMPLATES +# define SPROUT_TYPES_DETAIL_FUNCTIONAL_ARITHMETIC_BINARY_OP_VT_DECL(NAME) \ + template \ + SPROUT_STATIC_CONSTEXPR typename sprout::types::NAME::value_type SPROUT_PP_CAT(NAME, _v) = sprout::types::NAME::value; +#else // #if SPROUT_USE_VARIABLE_TEMPLATES +# define SPROUT_TYPES_DETAIL_FUNCTIONAL_ARITHMETIC_BINARY_OP_VT_DECL(NAME) +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_DETAIL_ARITHMETIC_OP_HPP diff --git a/sprout/type/functional/detail/comparison_op.hpp b/sprout/type/functional/detail/comparison_op.hpp new file mode 100644 index 00000000..3af3a610 --- /dev/null +++ b/sprout/type/functional/detail/comparison_op.hpp @@ -0,0 +1,36 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_DETAIL_COMPARISON_OP_HPP +#define SPROUT_TYPE_FUNCTIONAL_DETAIL_COMPARISON_OP_HPP + +#include +#include +#include +#include + +#define SPROUT_TYPES_DETAIL_FUNCTIONAL_COMPARISON_OP_DECL(NAME, OP) \ +namespace sprout { \ + namespace types { \ + template \ + struct NAME \ + : public sprout::integral_constant \ + {}; \ + typedef sprout::types::quote SPROUT_PP_CAT(NAME, _); \ + SPROUT_TYPES_DETAIL_FUNCTIONAL_COMPARISON_OP_VT_DECL(NAME) \ + } \ +} + +#if SPROUT_USE_VARIABLE_TEMPLATES +# define SPROUT_TYPES_DETAIL_FUNCTIONAL_COMPARISON_OP_VT_DECL(NAME) \ + template \ + SPROUT_STATIC_CONSTEXPR bool SPROUT_PP_CAT(NAME, _v) = sprout::types::NAME::value; +#else // #if SPROUT_USE_VARIABLE_TEMPLATES +# define SPROUT_TYPES_DETAIL_FUNCTIONAL_COMPARISON_OP_VT_DECL(NAME) +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_DETAIL_COMPARISON_OP_HPP diff --git a/sprout/type/functional/divides.hpp b/sprout/type/functional/divides.hpp new file mode 100644 index 00000000..a3ac5d58 --- /dev/null +++ b/sprout/type/functional/divides.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_DIVIDES_HPP +#define SPROUT_TYPE_FUNCTIONAL_DIVIDES_HPP + +#include +#include + +SPROUT_TYPES_DETAIL_FUNCTIONAL_ARITHMETIC_BINARY_OP_DECL(divides, /) + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_DIVIDES_HPP diff --git a/sprout/type/functional/equal_to.hpp b/sprout/type/functional/equal_to.hpp new file mode 100644 index 00000000..586b5608 --- /dev/null +++ b/sprout/type/functional/equal_to.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_EQUAL_TO_HPP +#define SPROUT_TYPE_FUNCTIONAL_EQUAL_TO_HPP + +#include +#include + +SPROUT_TYPES_DETAIL_FUNCTIONAL_COMPARISON_OP_DECL(equal_to, ==) + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_EQUAL_TO_HPP diff --git a/sprout/type/functional/greater.hpp b/sprout/type/functional/greater.hpp new file mode 100644 index 00000000..74e9819e --- /dev/null +++ b/sprout/type/functional/greater.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_GREATER_HPP +#define SPROUT_TYPE_FUNCTIONAL_GREATER_HPP + +#include +#include + +SPROUT_TYPES_DETAIL_FUNCTIONAL_COMPARISON_OP_DECL(greater, >) + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_GREATER_HPP diff --git a/sprout/type/functional/greater_equal.hpp b/sprout/type/functional/greater_equal.hpp new file mode 100644 index 00000000..d3ac2751 --- /dev/null +++ b/sprout/type/functional/greater_equal.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_GREATER_EQUAL_HPP +#define SPROUT_TYPE_FUNCTIONAL_GREATER_EQUAL_HPP + +#include +#include + +SPROUT_TYPES_DETAIL_FUNCTIONAL_COMPARISON_OP_DECL(greater_equal, >=) + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_GREATER_EQUAL_HPP diff --git a/sprout/type/functional/less.hpp b/sprout/type/functional/less.hpp index c5173ffe..22e6861d 100644 --- a/sprout/type/functional/less.hpp +++ b/sprout/type/functional/less.hpp @@ -9,34 +9,8 @@ #define SPROUT_TYPE_FUNCTIONAL_LESS_HPP #include -#include +#include -namespace sprout { - namespace types { - // - // less - // - template - struct less - : public sprout::integral_constant - {}; - - // - // less_ - // - struct less_ { - public: - template - struct apply - : public sprout::types::less - {}; - }; - -#if SPROUT_USE_VARIABLE_TEMPLATES - template - SPROUT_STATIC_CONSTEXPR bool less_v = sprout::types::less::value; -#endif // #if SPROUT_USE_VARIABLE_TEMPLATES - } // namespace types -} // namespace sprout +SPROUT_TYPES_DETAIL_FUNCTIONAL_COMPARISON_OP_DECL(less, <) #endif // #ifndef SPROUT_TYPE_FUNCTIONAL_LESS_HPP diff --git a/sprout/type/functional/less_equal.hpp b/sprout/type/functional/less_equal.hpp new file mode 100644 index 00000000..97452149 --- /dev/null +++ b/sprout/type/functional/less_equal.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_LESS_EQUAL_HPP +#define SPROUT_TYPE_FUNCTIONAL_LESS_EQUAL_HPP + +#include +#include + +SPROUT_TYPES_DETAIL_FUNCTIONAL_COMPARISON_OP_DECL(less_equal, <=) + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_LESS_EQUAL_HPP diff --git a/sprout/type/functional/minus.hpp b/sprout/type/functional/minus.hpp new file mode 100644 index 00000000..18cfd83f --- /dev/null +++ b/sprout/type/functional/minus.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_MINUS_HPP +#define SPROUT_TYPE_FUNCTIONAL_MINUS_HPP + +#include +#include + +SPROUT_TYPES_DETAIL_FUNCTIONAL_ARITHMETIC_BINARY_OP_DECL(minus, -) + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_MINUS_HPP diff --git a/sprout/type/functional/modulus.hpp b/sprout/type/functional/modulus.hpp new file mode 100644 index 00000000..87775ea7 --- /dev/null +++ b/sprout/type/functional/modulus.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_MODULUS_HPP +#define SPROUT_TYPE_FUNCTIONAL_MODULUS_HPP + +#include +#include + +SPROUT_TYPES_DETAIL_FUNCTIONAL_ARITHMETIC_BINARY_OP_DECL(modulus, %) + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_MODULUS_HPP diff --git a/sprout/type/functional/multiplies.hpp b/sprout/type/functional/multiplies.hpp new file mode 100644 index 00000000..e66621e8 --- /dev/null +++ b/sprout/type/functional/multiplies.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_MULTIPLIES_HPP +#define SPROUT_TYPE_FUNCTIONAL_MULTIPLIES_HPP + +#include +#include + +SPROUT_TYPES_DETAIL_FUNCTIONAL_ARITHMETIC_BINARY_OP_DECL(multiplies, *) + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_MULTIPLIES_HPP diff --git a/sprout/type/functional/not_equal_to.hpp b/sprout/type/functional/not_equal_to.hpp new file mode 100644 index 00000000..9ea8b135 --- /dev/null +++ b/sprout/type/functional/not_equal_to.hpp @@ -0,0 +1,16 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_FUNCTIONAL_NOT_EQUAL_TO_HPP +#define SPROUT_TYPE_FUNCTIONAL_NOT_EQUAL_TO_HPP + +#include +#include + +SPROUT_TYPES_DETAIL_FUNCTIONAL_COMPARISON_OP_DECL(not_equal_to, !=) + +#endif // #ifndef SPROUT_TYPE_FUNCTIONAL_NOT_EQUAL_TO_HPP diff --git a/sprout/type/functional/plus.hpp b/sprout/type/functional/plus.hpp index df99bd0b..955be67b 100644 --- a/sprout/type/functional/plus.hpp +++ b/sprout/type/functional/plus.hpp @@ -9,48 +9,8 @@ #define SPROUT_TYPE_FUNCTIONAL_PLUS_HPP #include -#include -#include +#include -namespace sprout { - namespace types { - // - // plus - // - template - struct plus - : public sprout::integral_constant - {}; - template - struct plus - : public sprout::integral_constant< - typename sprout::common_decay::type, - (T::value + U::value) - > - {}; - - // - // plus_mf - // - template - struct plus_mf { - public: - template - struct apply - : public sprout::types::plus - {}; - }; - - // - // plus_ - // - typedef sprout::types::plus_mf<> plus_; - -#if SPROUT_USE_VARIABLE_TEMPLATES - template - SPROUT_STATIC_CONSTEXPR typename sprout::types::plus::value_type plus_v = sprout::types::plus::value; -#endif // #if SPROUT_USE_VARIABLE_TEMPLATES - } // namespace types -} // namespace sprout +SPROUT_TYPES_DETAIL_FUNCTIONAL_ARITHMETIC_BINARY_OP_DECL(plus, +) #endif // #ifndef SPROUT_TYPE_FUNCTIONAL_PLUS_HPP diff --git a/sprout/type/self.hpp b/sprout/type/self.hpp new file mode 100644 index 00000000..6ceb8421 --- /dev/null +++ b/sprout/type/self.hpp @@ -0,0 +1,35 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_SELF_HPP +#define SPROUT_TYPE_SELF_HPP + +#include +#include + +namespace sprout { + namespace types { + // + // self + // + template class F> + struct self { + public: +#if SPROUT_USE_TEMPLATE_ALIASES + template + using apply = sprout::identity >; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct apply + : public sprout::identity > + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + }; + } // namespace types +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_SELF_HPP