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_REDUCE_HPP
0013 #define BOOST_ALGORITHM_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 template<class InputIterator, class T, class BinaryOperation>
0026 T reduce(InputIterator first, InputIterator last, T init, BinaryOperation bOp)
0027 {
0028 ;
0029 for (; first != last; ++first)
0030 init = bOp(init, *first);
0031 return init;
0032 }
0033
0034 template<class InputIterator, class T>
0035 T reduce(InputIterator first, InputIterator last, T init)
0036 {
0037 typedef typename std::iterator_traits<InputIterator>::value_type VT;
0038 return boost::algorithm::reduce(first, last, init, std::plus<VT>());
0039 }
0040
0041 template<class InputIterator>
0042 typename std::iterator_traits<InputIterator>::value_type
0043 reduce(InputIterator first, InputIterator last)
0044 {
0045 return boost::algorithm::reduce(first, last,
0046 typename std::iterator_traits<InputIterator>::value_type());
0047 }
0048
0049 template<class Range>
0050 typename boost::range_value<Range>::type
0051 reduce(const Range &r)
0052 {
0053 return boost::algorithm::reduce(boost::begin(r), boost::end(r));
0054 }
0055
0056
0057 template<class Range, class T>
0058 T reduce(const Range &r, T init)
0059 {
0060 return boost::algorithm::reduce(boost::begin (r), boost::end (r), init);
0061 }
0062
0063
0064
0065 template<class Range, class T, class BinaryOperation>
0066 T reduce(const Range &r, T init, BinaryOperation bOp)
0067 {
0068 return boost::algorithm::reduce(boost::begin(r), boost::end(r), init, bOp);
0069 }
0070
0071 }}
0072
0073 #endif