transform_exclusive_scan.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. Copyright (c) Marshall Clow 2017.
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. */
  6. /// \file transform_exclusive_scan.hpp
  7. /// \brief ????
  8. /// \author Marshall Clow
  9. #ifndef BOOST_ALGORITHM_TRANSFORM_EXCLUSIVE_SCAN_HPP
  10. #define BOOST_ALGORITHM_TRANSFORM_EXCLUSIVE_SCAN_HPP
  11. #include <functional> // for std::plus
  12. #include <iterator> // for std::iterator_traits
  13. #include <boost/config.hpp>
  14. #include <boost/range/begin.hpp>
  15. #include <boost/range/end.hpp>
  16. #include <boost/range/value_type.hpp>
  17. namespace boost { namespace algorithm {
  18. template<class InputIterator, class OutputIterator, class T,
  19. class BinaryOperation, class UnaryOperation>
  20. OutputIterator transform_exclusive_scan(InputIterator first, InputIterator last,
  21. OutputIterator result, T init,
  22. BinaryOperation bOp, UnaryOperation uOp)
  23. {
  24. if (first != last)
  25. {
  26. T saved = init;
  27. do
  28. {
  29. init = bOp(init, uOp(*first));
  30. *result = saved;
  31. saved = init;
  32. ++result;
  33. } while (++first != last);
  34. }
  35. return result;
  36. }
  37. }} // namespace boost and algorithm
  38. #endif // BOOST_ALGORITHM_TRANSFORM_EXCLUSIVE_SCAN_HPP