Back to home page

EIC code displayed by LXR

 
 

    


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_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 }} // namespace boost and algorithm
0060 
0061 #endif // BOOST_ALGORITHM_INCLUSIVE_SCAN_HPP