]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/algorithm/cxx17/transform_reduce.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / algorithm / cxx17 / transform_reduce.hpp
1 /*
2 Copyright (c) Marshall Clow 2017.
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt)
6 */
7
8 /// \file transform_reduce.hpp
9 /// \brief Combine the (transformed) elements of a sequence (or two) into a single value.
10 /// \author Marshall Clow
11
12 #ifndef BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP
13 #define BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP
14
15 #include <functional> // for std::plus
16 #include <iterator> // for std::iterator_traits
17
18 #include <boost/range/begin.hpp>
19 #include <boost/range/end.hpp>
20 #include <boost/range/value_type.hpp>
21
22 namespace boost { namespace algorithm {
23
24 template<class InputIterator1, class InputIterator2, class T,
25 class BinaryOperation1, class BinaryOperation2>
26 T transform_reduce(InputIterator1 first1, InputIterator1 last1,
27 InputIterator2 first2, T init,
28 BinaryOperation1 bOp1, BinaryOperation2 bOp2)
29 {
30 for (; first1 != last1; ++first1, (void) ++first2)
31 init = bOp1(init, bOp2(*first1, *first2));
32 return init;
33 }
34
35 template<class InputIterator, class T,
36 class BinaryOperation, class UnaryOperation>
37 T transform_reduce(InputIterator first, InputIterator last,
38 T init, BinaryOperation bOp, UnaryOperation uOp)
39 {
40 for (; first != last; ++first)
41 init = bOp(init, uOp(*first));
42 return init;
43 }
44
45 template<class InputIterator1, class InputIterator2, class T>
46 T transform_reduce(InputIterator1 first1, InputIterator1 last1,
47 InputIterator2 first2, T init)
48 {
49 return transform_reduce(first1, last1, first2, init,
50 std::plus<T>(), std::multiplies<T>());
51 }
52
53 }} // namespace boost and algorithm
54
55 #endif // BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP