]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/include/boost/compute/algorithm/replace_copy.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / compute / include / boost / compute / algorithm / replace_copy.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_REPLACE_COPY_HPP
12 #define BOOST_COMPUTE_ALGORITHM_REPLACE_COPY_HPP
13
14 #include <iterator>
15
16 #include <boost/compute/system.hpp>
17 #include <boost/compute/command_queue.hpp>
18 #include <boost/compute/algorithm/copy.hpp>
19 #include <boost/compute/algorithm/replace.hpp>
20
21 namespace boost {
22 namespace compute {
23
24 /// Copies the value in the range [\p first, \p last) to the range
25 /// beginning at \p result while replacing each instance of \p old_value
26 /// with \p new_value.
27 ///
28 /// \see replace()
29 template<class InputIterator, class OutputIterator, class T>
30 inline OutputIterator
31 replace_copy(InputIterator first,
32 InputIterator last,
33 OutputIterator result,
34 const T &old_value,
35 const T &new_value,
36 command_queue &queue = system::default_queue())
37 {
38 typedef typename std::iterator_traits<OutputIterator>::difference_type difference_type;
39
40 difference_type count = std::distance(first, last);
41 if(count == 0){
42 return result;
43 }
44
45 // copy data to result
46 ::boost::compute::copy(first, last, result, queue);
47
48 // replace in result
49 ::boost::compute::replace(result,
50 result + count,
51 old_value,
52 new_value,
53 queue);
54
55 // return iterator to the end of result
56 return result + count;
57 }
58
59 } // end compute namespace
60 } // end boost namespace
61
62 #endif // BOOST_COMPUTE_ALGORITHM_REPLACE_COPY_HPP