|
||||
File indexing completed on 2025-01-18 09:28:23
0001 /* 0002 Copyright (c) Marshall Clow 2017. 0003 0004 Distributed under the Boost Software License, Version 1.0. (See accompanying 0005 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0006 */ 0007 0008 /// \file transform_reduce.hpp 0009 /// \brief Combine the (transformed) elements of a sequence (or two) into a single value. 0010 /// \author Marshall Clow 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 /// \fn transform_inclusive_scan ( InputIterator first, InputIterator last, OutputIterator result, BinaryOperation bOp, UnaryOperation uOp, T init ) 0026 /// \brief Transforms elements from the input range with uOp and then combines 0027 /// those transformed elements with bOp such that the n-1th element and the nth 0028 /// element are combined. Inclusivity means that the nth element is included in 0029 /// the nth combination. 0030 /// \return The updated output iterator 0031 /// 0032 /// \param first The start of the input sequence 0033 /// \param last The end of the input sequence 0034 /// \param result The output iterator to write the results into 0035 /// \param bOp The operation for combining transformed input elements 0036 /// \param uOp The operation for transforming input elements 0037 /// \param init The initial value 0038 /// 0039 /// \note This function is part of the C++17 standard library 0040 template<class InputIterator, class OutputIterator, 0041 class BinaryOperation, class UnaryOperation, class T> 0042 OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last, 0043 OutputIterator result, 0044 BinaryOperation bOp, UnaryOperation uOp, 0045 T init) 0046 { 0047 for (; first != last; ++first, (void) ++result) { 0048 init = bOp(init, uOp(*first)); 0049 *result = init; 0050 } 0051 0052 return result; 0053 } 0054 0055 /// \fn transform_inclusive_scan ( InputIterator first, InputIterator last, OutputIterator result, BinaryOperation bOp, UnaryOperation uOp, T init ) 0056 /// \brief Transforms elements from the input range with uOp and then combines 0057 /// those transformed elements with bOp such that the n-1th element and the nth 0058 /// element are combined. Inclusivity means that the nth element is included in 0059 /// the nth combination. The first value will be used as the init. 0060 /// \return The updated output iterator 0061 /// 0062 /// \param first The start of the input sequence 0063 /// \param last The end of the input sequence 0064 /// \param result The output iterator to write the results into 0065 /// \param bOp The operation for combining transformed input elements 0066 /// \param uOp The operation for transforming input elements 0067 /// 0068 /// \note This function is part of the C++17 standard library 0069 template<class InputIterator, class OutputIterator, 0070 class BinaryOperation, class UnaryOperation> 0071 OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last, 0072 OutputIterator result, 0073 BinaryOperation bOp, UnaryOperation uOp) 0074 { 0075 if (first != last) { 0076 typename std::iterator_traits<InputIterator>::value_type init = uOp(*first); 0077 *result++ = init; 0078 if (++first != last) 0079 return boost::algorithm::transform_inclusive_scan 0080 (first, last, result, bOp, uOp, init); 0081 } 0082 0083 return result; 0084 } 0085 0086 0087 }} // namespace boost and algorithm 0088 0089 #endif // BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |