generate.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 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_GENERATE_HPP
  11. #define BOOST_COMPUTE_ALGORITHM_GENERATE_HPP
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/command_queue.hpp>
  14. #include <boost/compute/algorithm/copy.hpp>
  15. #include <boost/compute/iterator/function_input_iterator.hpp>
  16. #include <boost/compute/detail/iterator_range_size.hpp>
  17. namespace boost {
  18. namespace compute {
  19. /// Stores the result of \p generator for each element in the range
  20. /// [\p first, \p last).
  21. template<class OutputIterator, class Generator>
  22. inline void generate(OutputIterator first,
  23. OutputIterator last,
  24. Generator generator,
  25. command_queue &queue = system::default_queue())
  26. {
  27. size_t count = detail::iterator_range_size(first, last);
  28. if(count == 0){
  29. return;
  30. }
  31. ::boost::compute::copy(
  32. ::boost::compute::make_function_input_iterator(generator,
  33. first.get_index()),
  34. ::boost::compute::make_function_input_iterator(generator,
  35. last.get_index()),
  36. first,
  37. queue
  38. );
  39. }
  40. } // end compute namespace
  41. } // end boost namespace
  42. #endif // BOOST_COMPUTE_ALGORITHM_GENERATE_HPP