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_INCLUSIVE_SCAN_HPP
0013 #define BOOST_ALGORITHM_INCLUSIVE_SCAN_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 InputIterator, class OutputIterator, class T, class BinaryOperation>
0026 OutputIterator inclusive_scan(InputIterator first, InputIterator last,
0027 OutputIterator result, BinaryOperation bOp, T init)
0028 {
0029 for (; first != last; ++first, (void) ++result) {
0030 init = bOp(init, *first);
0031 *result = init;
0032 }
0033 return result;
0034 }
0035
0036
0037 template<class InputIterator, class OutputIterator, class BinaryOperation>
0038 OutputIterator inclusive_scan(InputIterator first, InputIterator last,
0039 OutputIterator result, BinaryOperation bOp)
0040 {
0041 if (first != last) {
0042 typename std::iterator_traits<InputIterator>::value_type init = *first;
0043 *result++ = init;
0044 if (++first != last)
0045 return boost::algorithm::inclusive_scan(first, last, result, bOp, init);
0046 }
0047
0048 return result;
0049 }
0050
0051 template<class InputIterator, class OutputIterator>
0052 OutputIterator inclusive_scan(InputIterator first, InputIterator last,
0053 OutputIterator result)
0054 {
0055 typedef typename std::iterator_traits<InputIterator>::value_type VT;
0056 return boost::algorithm::inclusive_scan(first, last, result, std::plus<VT>());
0057 }
0058
0059 }}
0060
0061 #endif