]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/replace_copy.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / 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 /// Space complexity: \Omega(1)
29 ///
30 /// \see replace()
31 template<class InputIterator, class OutputIterator, class T>
32 inline OutputIterator
33 replace_copy(InputIterator first,
34 InputIterator last,
35 OutputIterator result,
36 const T &old_value,
37 const T &new_value,
38 command_queue &queue = system::default_queue())
39 {
40 typedef typename std::iterator_traits<OutputIterator>::difference_type difference_type;
41
42 difference_type count = std::distance(first, last);
43 if(count == 0){
44 return result;
45 }
46
47 // copy data to result
48 ::boost::compute::copy(first, last, result, queue);
49
50 // replace in result
51 ::boost::compute::replace(result,
52 result + count,
53 old_value,
54 new_value,
55 queue);
56
57 // return iterator to the end of result
58 return result + count;
59 }
60
61 } // end compute namespace
62 } // end boost namespace
63
64 #endif // BOOST_COMPUTE_ALGORITHM_REPLACE_COPY_HPP