Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:57

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
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 /// Copies the value in the range [\p first, \p last) to the range
0028 /// beginning at \p result while replacing each instance of \p old_value
0029 /// with \p new_value.
0030 ///
0031 /// Space complexity: \Omega(1)
0032 ///
0033 /// \see replace()
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     // copy data to result
0054     ::boost::compute::copy(first, last, result, queue);
0055 
0056     // replace in result
0057     ::boost::compute::replace(result,
0058                               result + count,
0059                               old_value,
0060                               new_value,
0061                               queue);
0062 
0063     // return iterator to the end of result
0064     return result + count;
0065 }
0066 
0067 } // end compute namespace
0068 } // end boost namespace
0069 
0070 #endif // BOOST_COMPUTE_ALGORITHM_REPLACE_COPY_HPP