1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/sprout/numeric/inner_product.hpp

40 lines
1.3 KiB
C++
Raw Normal View History

2012-04-01 13:15:09 +00:00
#ifndef SPROUT_NUMERIC_INNNER_PRODUCT_HPP
#define SPROUT_NUMERIC_INNNER_PRODUCT_HPP
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 26.7.3 Inner product
2012-04-04 08:48:02 +00:00
template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryOperation1, typename BinaryOperation2>
2012-10-06 04:53:07 +00:00
inline SPROUT_CONSTEXPR T
inner_product(
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init,
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2
2012-04-01 13:15:09 +00:00
)
{
return first1 == last1 ? init
: sprout::inner_product(
2012-10-06 04:53:07 +00:00
sprout::next(first1), last1, sprout::next(first2), binary_op1(init, binary_op2(*first1, *first2)),
binary_op1, binary_op2
2012-04-01 13:15:09 +00:00
)
;
}
2012-04-04 08:48:02 +00:00
template<typename InputIterator1, typename InputIterator2, typename T>
2012-10-06 04:53:07 +00:00
inline SPROUT_CONSTEXPR T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init) {
2012-04-01 13:15:09 +00:00
return sprout::inner_product(
2012-10-06 04:53:07 +00:00
first1, last1, first2, init,
2012-04-01 13:15:09 +00:00
sprout::plus<typename std::iterator_traits<InputIterator1>::value_type>(),
NS_SSCRISK_CEL_OR_SPROUT::multiplies<typename std::iterator_traits<InputIterator1>::value_type>()
);
}
} // namespace sprout
#endif // #ifndef SPROUT_NUMERIC_INNNER_PRODUCT_HPP