/*============================================================================= Copyright (c) 2011-2018 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_ARITHMETIC_HPP #define SPROUT_VALARRAY_ARITHMETIC_HPP #include #include #include #include #include #include #include #include #include #include #include namespace sprout { // // operator+ // template inline SPROUT_CONSTEXPR sprout::valarray operator+(sprout::valarray const& lhs, sprout::valarray const& rhs) { return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::plus<>()); } template inline SPROUT_CONSTEXPR sprout::valarray operator+(sprout::valarray const& lhs, T const& rhs) { return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::plus<>(), rhs)); } template inline SPROUT_CONSTEXPR sprout::valarray operator+(T const& lhs, sprout::valarray const& rhs) { return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::plus<>(), lhs)); } // // operator- // template inline SPROUT_CONSTEXPR sprout::valarray operator-(sprout::valarray const& lhs, sprout::valarray const& rhs) { return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::minus<>()); } template inline SPROUT_CONSTEXPR sprout::valarray operator-(sprout::valarray const& lhs, T const& rhs) { return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::minus<>(), rhs)); } template inline SPROUT_CONSTEXPR sprout::valarray operator-(T const& lhs, sprout::valarray const& rhs) { return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::minus<>(), lhs)); } // // operator* // template inline SPROUT_CONSTEXPR sprout::valarray operator*(sprout::valarray const& lhs, sprout::valarray const& rhs) { return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::multiplies<>()); } template inline SPROUT_CONSTEXPR sprout::valarray operator*(sprout::valarray const& lhs, T const& rhs) { return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::multiplies<>(), rhs)); } template inline SPROUT_CONSTEXPR sprout::valarray operator*(T const& lhs, sprout::valarray const& rhs) { return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::multiplies<>(), lhs)); } // // operator/ // template inline SPROUT_CONSTEXPR sprout::valarray operator/(sprout::valarray const& lhs, sprout::valarray const& rhs) { return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::divides<>()); } template inline SPROUT_CONSTEXPR sprout::valarray operator/(sprout::valarray const& lhs, T const& rhs) { return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::divides<>(), rhs)); } template inline SPROUT_CONSTEXPR sprout::valarray operator/(T const& lhs, sprout::valarray const& rhs) { return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::divides<>(), lhs)); } // // operator% // template inline SPROUT_CONSTEXPR sprout::valarray operator%(sprout::valarray const& lhs, sprout::valarray const& rhs) { return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::modulus<>()); } template inline SPROUT_CONSTEXPR sprout::valarray operator%(sprout::valarray const& lhs, T const& rhs) { return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::modulus<>(), rhs)); } template inline SPROUT_CONSTEXPR sprout::valarray operator%(T const& lhs, sprout::valarray const& rhs) { return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::modulus<>(), lhs)); } } // namespace sprout #endif // #ifndef SPROUT_VALARRAY_ARITHMETIC_HPP