2 Copyright (c) Marshall Clow 2017.
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 /// \file transform_reduce.hpp
9 /// \brief Combine the (transformed) elements of a sequence (or two) into a single value.
10 /// \author Marshall Clow
12 #ifndef BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP
13 #define BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP
15 #include <functional> // for std::plus
16 #include <iterator> // for std::iterator_traits
18 #include <boost/config.hpp>
19 #include <boost/range/begin.hpp>
20 #include <boost/range/end.hpp>
21 #include <boost/range/value_type.hpp>
23 namespace boost { namespace algorithm {
25 template<class InputIterator, class OutputIterator,
26 class BinaryOperation, class UnaryOperation, class T>
27 OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
28 OutputIterator result,
29 BinaryOperation bOp, UnaryOperation uOp,
32 for (; first != last; ++first, (void) ++result) {
33 init = bOp(init, uOp(*first));
40 template<class InputIterator, class OutputIterator,
41 class BinaryOperation, class UnaryOperation>
42 OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
43 OutputIterator result,
44 BinaryOperation bOp, UnaryOperation uOp)
47 typename std::iterator_traits<InputIterator>::value_type init = uOp(*first);
50 return boost::algorithm::transform_inclusive_scan
51 (first, last, result, bOp, uOp, init);
58 }} // namespace boost and algorithm
60 #endif // BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP