File indexing completed on 2025-01-18 09:29:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_ALGORITHM_REPLACE_COPY_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_REPLACE_COPY_HPP
0013
0014 #include <iterator>
0015
0016 #include <boost/static_assert.hpp>
0017
0018 #include <boost/compute/system.hpp>
0019 #include <boost/compute/command_queue.hpp>
0020 #include <boost/compute/algorithm/copy.hpp>
0021 #include <boost/compute/algorithm/replace.hpp>
0022 #include <boost/compute/type_traits/is_device_iterator.hpp>
0023
0024 namespace boost {
0025 namespace compute {
0026
0027
0028
0029
0030
0031
0032
0033
0034 template<class InputIterator, class OutputIterator, class T>
0035 inline OutputIterator
0036 replace_copy(InputIterator first,
0037 InputIterator last,
0038 OutputIterator result,
0039 const T &old_value,
0040 const T &new_value,
0041 command_queue &queue = system::default_queue())
0042 {
0043 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0044 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0045
0046 typedef typename std::iterator_traits<OutputIterator>::difference_type difference_type;
0047
0048 difference_type count = std::distance(first, last);
0049 if(count == 0){
0050 return result;
0051 }
0052
0053
0054 ::boost::compute::copy(first, last, result, queue);
0055
0056
0057 ::boost::compute::replace(result,
0058 result + count,
0059 old_value,
0060 new_value,
0061 queue);
0062
0063
0064 return result + count;
0065 }
0066
0067 }
0068 }
0069
0070 #endif