]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_GENERATE_HPP | |
12 | #define BOOST_COMPUTE_ALGORITHM_GENERATE_HPP | |
13 | ||
92f5a8d4 TL |
14 | #include <boost/static_assert.hpp> |
15 | ||
7c673cae FG |
16 | #include <boost/compute/system.hpp> |
17 | #include <boost/compute/command_queue.hpp> | |
18 | #include <boost/compute/algorithm/copy.hpp> | |
19 | #include <boost/compute/iterator/function_input_iterator.hpp> | |
20 | #include <boost/compute/detail/iterator_range_size.hpp> | |
92f5a8d4 | 21 | #include <boost/compute/type_traits/is_device_iterator.hpp> |
7c673cae FG |
22 | |
23 | namespace boost { | |
24 | namespace compute { | |
25 | ||
26 | /// Stores the result of \p generator for each element in the range | |
27 | /// [\p first, \p last). | |
b32b8144 FG |
28 | /// |
29 | /// Space complexity: \Omega(1) | |
7c673cae FG |
30 | template<class OutputIterator, class Generator> |
31 | inline void generate(OutputIterator first, | |
32 | OutputIterator last, | |
33 | Generator generator, | |
34 | command_queue &queue = system::default_queue()) | |
35 | { | |
92f5a8d4 | 36 | BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value); |
7c673cae FG |
37 | size_t count = detail::iterator_range_size(first, last); |
38 | if(count == 0){ | |
39 | return; | |
40 | } | |
41 | ||
42 | ::boost::compute::copy( | |
43 | ::boost::compute::make_function_input_iterator(generator, | |
44 | first.get_index()), | |
45 | ::boost::compute::make_function_input_iterator(generator, | |
46 | last.get_index()), | |
47 | first, | |
48 | queue | |
49 | ); | |
50 | } | |
51 | ||
52 | } // end compute namespace | |
53 | } // end boost namespace | |
54 | ||
55 | #endif // BOOST_COMPUTE_ALGORITHM_GENERATE_HPP |