iota.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_IOTA_HPP
  11. #define BOOST_COMPUTE_ALGORITHM_IOTA_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/counting_iterator.hpp>
  16. namespace boost {
  17. namespace compute {
  18. /// Fills the range [\p first, \p last) with sequential values starting at
  19. /// \p value.
  20. ///
  21. /// For example, the following code:
  22. /// \snippet test/test_iota.cpp iota
  23. ///
  24. /// Will fill \c vec with the values (\c 0, \c 1, \c 2, \c ...).
  25. template<class BufferIterator, class T>
  26. inline void iota(BufferIterator first,
  27. BufferIterator last,
  28. const T &value,
  29. command_queue &queue = system::default_queue())
  30. {
  31. T count = static_cast<T>(detail::iterator_range_size(first, last));
  32. copy(
  33. ::boost::compute::make_counting_iterator(value),
  34. ::boost::compute::make_counting_iterator(value + count),
  35. first,
  36. queue
  37. );
  38. }
  39. } // end compute namespace
  40. } // end boost namespace
  41. #endif // BOOST_COMPUTE_ALGORITHM_IOTA_HPP