/*============================================================================= Copyright (c) 2011-2016 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_VALARRAY_POWER_HPP #define SPROUT_VALARRAY_POWER_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include namespace sprout_math_detail { using sprout::math::cbrt; using sprout::math::abs; using sprout::math::hypot; using sprout::math::pow; using sprout::math::sqrt; using sprout::math::log_a; using sprout::abs; template inline SPROUT_CONSTEXPR decltype(cbrt(std::declval())) call_cbrt(T&& x) SPROUT_NOEXCEPT_IF_EXPR(cbrt(std::declval())) { return cbrt(SPROUT_FORWARD(T, x)); } template inline SPROUT_CONSTEXPR decltype(abs(std::declval())) call_abs(T&& x) SPROUT_NOEXCEPT_IF_EXPR(abs(std::declval())) { return abs(SPROUT_FORWARD(T, x)); } template inline SPROUT_CONSTEXPR decltype(hypot(std::declval(), std::declval())) call_hypot(T&& x, U&& y) SPROUT_NOEXCEPT_IF_EXPR(hypot(std::declval(), std::declval())) { return hypot(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y)); } template inline SPROUT_CONSTEXPR decltype(pow(std::declval(), std::declval())) call_pow(T&& x, U&& y) SPROUT_NOEXCEPT_IF_EXPR(pow(std::declval(), std::declval())) { return pow(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y)); } template inline SPROUT_CONSTEXPR decltype(sqrt(std::declval())) call_sqrt(T&& x) SPROUT_NOEXCEPT_IF_EXPR(sqrt(std::declval())) { return sqrt(SPROUT_FORWARD(T, x)); } template inline SPROUT_CONSTEXPR decltype(log_a(std::declval(), std::declval())) call_log_a(T&& x, U&& y) SPROUT_NOEXCEPT_IF_EXPR(log_a(std::declval(), std::declval())) { return log_a(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y)); } } // namespace sprout namespace sprout { namespace detail { struct cbrt_f : public sprout::transparent<> { public: template SPROUT_CONSTEXPR decltype(sprout_math_detail::call_cbrt(std::declval())) operator()(T&& x) SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_cbrt(std::declval())) { return sprout_math_detail::call_cbrt(SPROUT_FORWARD(T, x)); } }; struct abs_f : public sprout::transparent<> { public: template SPROUT_CONSTEXPR decltype(sprout_math_detail::call_abs(std::declval())) operator()(T&& x) SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_abs(std::declval())) { return sprout_math_detail::call_abs(SPROUT_FORWARD(T, x)); } }; struct hypot_f : public sprout::transparent<> { public: template SPROUT_CONSTEXPR decltype(sprout_math_detail::call_hypot(std::declval(), std::declval())) operator()(T&& x, U&& y) SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_hypot(std::declval(), std::declval())) { return sprout_math_detail::call_hypot(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y)); } }; struct pow_f : public sprout::transparent<> { public: template SPROUT_CONSTEXPR decltype(sprout_math_detail::call_pow(std::declval(), std::declval())) operator()(T&& x, U&& y) SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_pow(std::declval(), std::declval())) { return sprout_math_detail::call_pow(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y)); } }; struct sqrt_f : public sprout::transparent<> { public: template SPROUT_CONSTEXPR decltype(sprout_math_detail::call_sqrt(std::declval())) operator()(T&& x) SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_sqrt(std::declval())) { return sprout_math_detail::call_sqrt(SPROUT_FORWARD(T, x)); } }; struct log_a_f : public sprout::transparent<> { public: template SPROUT_CONSTEXPR decltype(sprout_math_detail::call_log_a(std::declval(), std::declval())) operator()(T&& x, U&& y) SPROUT_NOEXCEPT_IF_EXPR(sprout_math_detail::call_log_a(std::declval(), std::declval())) { return sprout_math_detail::call_log_a(SPROUT_FORWARD(T, x), SPROUT_FORWARD(U, y)); } }; } // namespace detail // // cbrt // template inline SPROUT_CONSTEXPR sprout::valarray cbrt(sprout::valarray const& x) { return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::cbrt_f()); } // // abs // template inline SPROUT_CONSTEXPR sprout::valarray abs(sprout::valarray const& x) { return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::abs_f()); } // // hypot // template inline SPROUT_CONSTEXPR sprout::valarray hypot(sprout::valarray const& x, sprout::valarray const& y) { return sprout::fixed::transform(x.begin(), x.end(), y.end(), x, sprout::detail::hypot_f()); } template inline SPROUT_CONSTEXPR sprout::valarray hypot(sprout::valarray const& x, T const& y) { return sprout::fixed::transform(x.begin(), x.end(), x, sprout::bind2nd(sprout::detail::hypot_f(), y)); } template inline SPROUT_CONSTEXPR sprout::valarray hypot(T const& x, sprout::valarray const& y) { return sprout::fixed::transform(y.begin(), y.end(), y, sprout::bind1st(sprout::detail::hypot_f(), x)); } // // pow // template inline SPROUT_CONSTEXPR sprout::valarray pow(sprout::valarray const& x, sprout::valarray const& y) { return sprout::fixed::transform(x.begin(), x.end(), y.end(), x, sprout::detail::pow_f()); } template inline SPROUT_CONSTEXPR sprout::valarray pow(sprout::valarray const& x, T const& y) { return sprout::fixed::transform(x.begin(), x.end(), x, sprout::bind2nd(sprout::detail::pow_f(), y)); } template inline SPROUT_CONSTEXPR sprout::valarray pow(T const& x, sprout::valarray const& y) { return sprout::fixed::transform(y.begin(), y.end(), y, sprout::bind1st(sprout::detail::pow_f(), x)); } // // sqrt // template inline SPROUT_CONSTEXPR sprout::valarray sqrt(sprout::valarray const& x) { return sprout::fixed::transform(x.begin(), x.end(), x, sprout::detail::sqrt_f()); } // // log_a // template inline SPROUT_CONSTEXPR sprout::valarray log_a(sprout::valarray const& x, sprout::valarray const& y) { return sprout::fixed::transform(x.begin(), x.end(), y.end(), x, sprout::detail::log_a_f()); } template inline SPROUT_CONSTEXPR sprout::valarray log_a(sprout::valarray const& x, T const& y) { return sprout::fixed::transform(x.begin(), x.end(), x, sprout::bind2nd(sprout::detail::log_a_f(), y)); } template inline SPROUT_CONSTEXPR sprout::valarray log_a(T const& x, sprout::valarray const& y) { return sprout::fixed::transform(y.begin(), y.end(), y, sprout::bind1st(sprout::detail::log_a_f(), x)); } } // namespace sprout #endif // #ifndef SPROUT_VALARRAY_POWER_HPP