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
11 #ifndef BOOST_COMPUTE_ALGORITHM_COPY_N_HPP
12 #define BOOST_COMPUTE_ALGORITHM_COPY_N_HPP
13
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/command_queue.hpp>
16 #include <boost/compute/algorithm/copy.hpp>
17
18 namespace boost {
19 namespace compute {
20
21 /// Copies \p count elements from \p first to \p result.
22 ///
23 /// For example, to copy four values from the host to the device:
24 /// \code
25 /// // values on the host and vector on the device
26 /// float values[4] = { 1.f, 2.f, 3.f, 4.f };
27 /// boost::compute::vector<float> vec(4, context);
28 ///
29 /// // copy from the host to the device
30 /// boost::compute::copy_n(values, 4, vec.begin(), queue);
31 /// \endcode
32 ///
33 /// Space complexity: \Omega(1)
34 ///
35 /// \see copy()
36 template<class InputIterator, class Size, class OutputIterator>
copy_n(InputIterator first,Size count,OutputIterator result,command_queue & queue=system::default_queue (),const wait_list & events=wait_list ())37 inline OutputIterator copy_n(InputIterator first,
38 Size count,
39 OutputIterator result,
40 command_queue &queue = system::default_queue(),
41 const wait_list &events = wait_list())
42 {
43 typedef typename std::iterator_traits<InputIterator>::difference_type difference_type;
44
45 return ::boost::compute::copy(first,
46 first + static_cast<difference_type>(count),
47 result,
48 queue,
49 events);
50 }
51
52 } // end compute namespace
53 } // end boost namespace
54
55 #endif // BOOST_COMPUTE_ALGORITHM_COPY_N_HPP
56