]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/for_each.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / algorithm / for_each.hpp
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_FOR_EACH_HPP
12 #define BOOST_COMPUTE_ALGORITHM_FOR_EACH_HPP
13
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/command_queue.hpp>
16 #include <boost/compute/detail/meta_kernel.hpp>
17 #include <boost/compute/detail/iterator_range_size.hpp>
18
19 namespace boost {
20 namespace compute {
21 namespace detail {
22
23 template<class InputIterator, class Function>
24 struct for_each_kernel : public meta_kernel
25 {
26 for_each_kernel(InputIterator first, InputIterator last, Function function)
27 : meta_kernel("for_each")
28 {
29 // store range size
30 m_count = detail::iterator_range_size(first, last);
31
32 // setup kernel source
33 *this << function(first[get_global_id(0)]) << ";\n";
34 }
35
36 void exec(command_queue &queue)
37 {
38 exec_1d(queue, 0, m_count);
39 }
40
41 size_t m_count;
42 };
43
44 } // end detail namespace
45
46 /// Calls \p function on each element in the range [\p first, \p last).
47 ///
48 /// Space complexity: \Omega(1)
49 ///
50 /// \see transform()
51 template<class InputIterator, class UnaryFunction>
52 inline UnaryFunction for_each(InputIterator first,
53 InputIterator last,
54 UnaryFunction function,
55 command_queue &queue = system::default_queue())
56 {
57 detail::for_each_kernel<InputIterator, UnaryFunction> kernel(first, last, function);
58
59 kernel.exec(queue);
60
61 return function;
62 }
63
64 } // end compute namespace
65 } // end boost namespace
66
67 #endif // BOOST_COMPUTE_ALGORITHM_FOR_EACH_HPP