for_each_n.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
  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_ALGORITHM_FOR_EACH_N_HPP
  11. #define BOOST_COMPUTE_ALGORITHM_FOR_EACH_N_HPP
  12. #include <boost/static_assert.hpp>
  13. #include <boost/compute/algorithm/for_each.hpp>
  14. #include <boost/compute/type_traits/is_device_iterator.hpp>
  15. namespace boost {
  16. namespace compute {
  17. /// Calls \p function on each element in the range [\p first, \p first
  18. /// \c + \p count).
  19. ///
  20. /// Space complexity: \Omega(1)
  21. ///
  22. /// \see for_each()
  23. template<class InputIterator, class Size, class UnaryFunction>
  24. inline UnaryFunction for_each_n(InputIterator first,
  25. Size count,
  26. UnaryFunction function,
  27. command_queue &queue = system::default_queue())
  28. {
  29. BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
  30. return ::boost::compute::for_each(first, first + count, function, queue);
  31. }
  32. } // end compute namespace
  33. } // end boost namespace
  34. #endif // BOOST_COMPUTE_ALGORITHM_FOR_EACH_N_HPP