1 /* 2 Copyright (c) Marshall Clow 2017. 3 4 Distributed under the Boost Software License, Version 1.0. (See accompanying 5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 */ 7 8 /// \file exclusive_scan.hpp 9 /// \brief ??? 10 /// \author Marshall Clow 11 12 #ifndef BOOST_ALGORITHM_EXCLUSIVE_SCAN_HPP 13 #define BOOST_ALGORITHM_EXCLUSIVE_SCAN_HPP 14 15 #include <functional> // for std::plus 16 #include <iterator> // for std::iterator_traits 17 18 #include <boost/config.hpp> 19 #include <boost/range/begin.hpp> 20 #include <boost/range/end.hpp> 21 #include <boost/range/value_type.hpp> 22 23 namespace boost { namespace algorithm { 24 25 template<class InputIterator, class OutputIterator, class T, class BinaryOperation> 26 OutputIterator exclusive_scan(InputIterator first, InputIterator last, 27 OutputIterator result, T init, BinaryOperation bOp) 28 { 29 if (first != last) 30 { 31 T saved = init; mismatch(InputIterator1 first1,InputIterator1 last1,InputIterator2 first2,InputIterator2 last2,BinaryPredicate pred)32 do 33 { 34 init = bOp(init, *first); 35 *result = saved; 36 saved = init; 37 ++result; 38 } while (++first != last); 39 } 40 return result; 41 } 42 43 template<class InputIterator, class OutputIterator, class T> 44 OutputIterator exclusive_scan(InputIterator first, InputIterator last, 45 OutputIterator result, T init) 46 { 47 typedef typename std::iterator_traits<InputIterator>::value_type VT; 48 return boost::algorithm::exclusive_scan(first, last, result, init, std::plus<VT>()); 49 } 50 51 }} // namespace boost and algorithm mismatch(InputIterator1 first1,InputIterator1 last1,InputIterator2 first2,InputIterator2 last2)52 53 #endif // BOOST_ALGORITHM_EXCLUSIVE_SCAN_HPP 54