From 635145eda5f52d09aa0def239f2389e19d7761d2 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Wed, 20 Jun 2012 23:18:41 +0900 Subject: [PATCH] fix math::float_promote --- sprout/functional/arithmetic.hpp | 1 + sprout/functional/posite.hpp | 22 +++++++++++++++ sprout/math/float_promote.hpp | 47 ++++++++++++++------------------ 3 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 sprout/functional/posite.hpp diff --git a/sprout/functional/arithmetic.hpp b/sprout/functional/arithmetic.hpp index a6b40ff7..b36707cf 100644 --- a/sprout/functional/arithmetic.hpp +++ b/sprout/functional/arithmetic.hpp @@ -8,5 +8,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_FUNCTIONAL_ARITHMETIC_HPP diff --git a/sprout/functional/posite.hpp b/sprout/functional/posite.hpp new file mode 100644 index 00000000..81c92778 --- /dev/null +++ b/sprout/functional/posite.hpp @@ -0,0 +1,22 @@ +#ifndef SPROUT_FUNCTIONAL_POSITE_HPP +#define SPROUT_FUNCTIONAL_POSITE_HPP + +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + // 20.8.4 Arithmetic operations + template + struct posite { + public: + typedef T argument_type; + typedef T result_type; + public: + SPROUT_CONSTEXPR T operator()(T const& x) const { + return +x; + } + }; +} // namespace sprout + +#endif // #ifndef SPROUT_FUNCTIONAL_POSITE_HPP diff --git a/sprout/math/float_promote.hpp b/sprout/math/float_promote.hpp index 5f86f3c9..dc880706 100644 --- a/sprout/math/float_promote.hpp +++ b/sprout/math/float_promote.hpp @@ -7,36 +7,31 @@ namespace sprout { namespace math { namespace detail { - template - struct float_promote_impl {}; - template - struct float_promote_impl + template + struct float_promote2 : public std::conditional< - (std::is_same::value || std::is_same::value), - long double, - double - > - {}; - template - struct float_promote_impl - : public sprout::math::detail::float_promote_impl< - std::is_arithmetic::value, + (std::is_same::value || std::is_same::value), + std::common_type, typename std::conditional< - (std::is_same::value || std::is_same::value), - long double, + (std::is_same::value && std::is_same::value), + float, double - >::type, + > + >::type + { + static_assert(std::is_arithmetic::value, "float_promote requires arithmetic type."); + }; + + template + struct float_promote_impl + : public sprout::math::detail::float_promote_impl< + typename sprout::math::detail::float_promote2::type, Tail... > {}; - - template - struct float_promote - : public sprout::math::detail::float_promote_impl< - std::is_arithmetic::value, - double, - Head, Tail... - > + template + struct float_promote_impl + : public sprout::math::detail::float_promote2 {}; } // namespace detail @@ -45,8 +40,8 @@ namespace sprout { // template struct float_promote - : public sprout::math::detail::float_promote< - typename std::remove_cv::type... + : public sprout::math::detail::float_promote_impl< + float, typename std::remove_cv::type... > {}; } // namespace math