| 1 | /* |
| 2 | Copyright (c) Marshall Clow 2017. |
| 3 | |
| 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) |
| 6 | */ |
| 7 | |
| 8 | /// \file transform_exclusive_scan.hpp |
| 9 | /// \brief ???? |
| 10 | /// \author Marshall Clow |
| 11 | |
| 12 | #ifndef BOOST_ALGORITHM_TRANSFORM_EXCLUSIVE_SCAN_HPP |
| 13 | #define BOOST_ALGORITHM_TRANSFORM_EXCLUSIVE_SCAN_HPP |
| 14 | |
| 15 | #include <functional> // for std::plus |
| 16 | #include <iterator> // for std::iterator_traits |
| 17 | |
| 18 | #include <boost/config.hpp> |
| 19 | #include <boost/range/begin.hpp> |
| 20 | #include <boost/range/end.hpp> |
| 21 | #include <boost/range/value_type.hpp> |
| 22 | |
| 23 | namespace boost { namespace algorithm { |
| 24 | |
| 25 | /// \fn transform_exclusive_scan ( InputIterator first, InputIterator last, OutputIterator result, BinaryOperation bOp, UnaryOperation uOp, T init ) |
| 26 | /// \brief Transforms elements from the input range with uOp and then combines |
| 27 | /// those transformed elements with bOp such that the n-1th element and the nth |
| 28 | /// element are combined. Exclusivity means that the nth element is not |
| 29 | /// included in the nth combination. |
| 30 | /// \return The updated output iterator |
| 31 | /// |
| 32 | /// \param first The start of the input sequence |
| 33 | /// \param last The end of the input sequence |
| 34 | /// \param result The output iterator to write the results into |
| 35 | /// \param bOp The operation for combining transformed input elements |
| 36 | /// \param uOp The operation for transforming input elements |
| 37 | /// \param init The initial value |
| 38 | /// |
| 39 | /// \note This function is part of the C++17 standard library |
| 40 | template<class InputIterator, class OutputIterator, class T, |
| 41 | class BinaryOperation, class UnaryOperation> |
| 42 | OutputIterator transform_exclusive_scan(InputIterator first, InputIterator last, |
| 43 | OutputIterator result, T init, |
| 44 | BinaryOperation bOp, UnaryOperation uOp) |
| 45 | { |
| 46 | if (first != last) |
| 47 | { |
| 48 | T saved = init; |
| 49 | do |
| 50 | { |
| 51 | init = bOp(init, uOp(*first)); |
| 52 | *result = saved; |
| 53 | saved = init; |
| 54 | ++result; |
| 55 | } while (++first != last); |
| 56 | } |
| 57 | return result; |
| 58 | } |
| 59 | |
| 60 | }} // namespace boost and algorithm |
| 61 | |
| 62 | #endif // BOOST_ALGORITHM_TRANSFORM_EXCLUSIVE_SCAN_HPP |
| 63 | |