1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_ALGORITHM_REPLACE_COPY_HPP
12 #define BOOST_COMPUTE_ALGORITHM_REPLACE_COPY_HPP
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>
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.
28 /// Space complexity: \Omega(1)
31 template<class InputIterator, class OutputIterator, class T>
33 replace_copy(InputIterator first,
35 OutputIterator result,
38 command_queue &queue = system::default_queue())
40 typedef typename std::iterator_traits<OutputIterator>::difference_type difference_type;
42 difference_type count = std::distance(first, last);
47 // copy data to result
48 ::boost::compute::copy(first, last, result, queue);
51 ::boost::compute::replace(result,
57 // return iterator to the end of result
58 return result + count;
61 } // end compute namespace
62 } // end boost namespace
64 #endif // BOOST_COMPUTE_ALGORITHM_REPLACE_COPY_HPP