File indexing completed on 2025-01-18 09:28:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP
0013 #define BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP
0014
0015 #include <functional> // for std::plus
0016 #include <iterator> // for std::iterator_traits
0017
0018 #include <boost/config.hpp>
0019 #include <boost/range/begin.hpp>
0020 #include <boost/range/end.hpp>
0021 #include <boost/range/value_type.hpp>
0022
0023 namespace boost { namespace algorithm {
0024
0025 template<class InputIterator1, class InputIterator2, class T,
0026 class BinaryOperation1, class BinaryOperation2>
0027 T transform_reduce(InputIterator1 first1, InputIterator1 last1,
0028 InputIterator2 first2, T init,
0029 BinaryOperation1 bOp1, BinaryOperation2 bOp2)
0030 {
0031 for (; first1 != last1; ++first1, (void) ++first2)
0032 init = bOp1(init, bOp2(*first1, *first2));
0033 return init;
0034 }
0035
0036 template<class InputIterator, class T,
0037 class BinaryOperation, class UnaryOperation>
0038 T transform_reduce(InputIterator first, InputIterator last,
0039 T init, BinaryOperation bOp, UnaryOperation uOp)
0040 {
0041 for (; first != last; ++first)
0042 init = bOp(init, uOp(*first));
0043 return init;
0044 }
0045
0046 template<class InputIterator1, class InputIterator2, class T>
0047 T transform_reduce(InputIterator1 first1, InputIterator1 last1,
0048 InputIterator2 first2, T init)
0049 {
0050 return boost::algorithm::transform_reduce(first1, last1, first2, init,
0051 std::plus<T>(), std::multiplies<T>());
0052 }
0053
0054 }}
0055
0056 #endif