clamp_range.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <[email protected]>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_EXPERIMENTAL_CLAMP_RANGE_HPP
  11. #define BOOST_COMPUTE_EXPERIMENTAL_CLAMP_RANGE_HPP
  12. #include <iterator>
  13. #include <boost/compute/lambda.hpp>
  14. #include <boost/compute/algorithm/transform.hpp>
  15. namespace boost {
  16. namespace compute {
  17. namespace experimental {
  18. template<class InputIterator, class OutputIterator>
  19. inline OutputIterator
  20. clamp_range(InputIterator first,
  21. InputIterator last,
  22. OutputIterator result,
  23. typename std::iterator_traits<InputIterator>::value_type lo,
  24. typename std::iterator_traits<InputIterator>::value_type hi,
  25. command_queue &queue)
  26. {
  27. using ::boost::compute::lambda::_1;
  28. using ::boost::compute::lambda::_2;
  29. using ::boost::compute::lambda::clamp;
  30. return ::boost::compute::transform(
  31. first,
  32. last,
  33. result,
  34. clamp(_1, lo, hi),
  35. queue
  36. );
  37. }
  38. } // end experimental namespace
  39. } // end compute namespace
  40. } // end boost namespace
  41. #endif // BOOST_COMPUTE_EXPERIMENTAL_CLAMP_RANGE_HPP