Back to home page

EIC code displayed by LXR

 
 

    


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

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_SWAP_RANGES_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_SWAP_RANGES_HPP
0013 
0014 #include <boost/static_assert.hpp>
0015 
0016 #include <boost/compute/system.hpp>
0017 #include <boost/compute/command_queue.hpp>
0018 #include <boost/compute/algorithm/copy.hpp>
0019 #include <boost/compute/container/vector.hpp>
0020 #include <boost/compute/type_traits/is_device_iterator.hpp>
0021 
0022 namespace boost {
0023 namespace compute {
0024 
0025 /// Swaps the elements in the range [\p first1, \p last1) with the
0026 /// elements in the range beginning at \p first2.
0027 ///
0028 /// Space complexity: \Omega(distance(\p first1, \p last1))
0029 template<class Iterator1, class Iterator2>
0030 inline Iterator2 swap_ranges(Iterator1 first1,
0031                              Iterator1 last1,
0032                              Iterator2 first2,
0033                              command_queue &queue = system::default_queue())
0034 {
0035     BOOST_STATIC_ASSERT(is_device_iterator<Iterator1>::value);
0036     BOOST_STATIC_ASSERT(is_device_iterator<Iterator2>::value);
0037 
0038     typedef typename std::iterator_traits<Iterator1>::value_type value_type;
0039 
0040     Iterator2 last2 = first2 + std::distance(first1, last1);
0041 
0042     ::boost::compute::vector<value_type> tmp(first1, last1, queue);
0043     ::boost::compute::copy(first2, last2, first1, queue);
0044     ::boost::compute::copy(tmp.begin(), tmp.end(), first2, queue);
0045 
0046     return last2;
0047 }
0048 
0049 } // end compute namespace
0050 } // end boost namespace
0051 
0052 #endif // BOOST_COMPUTE_ALGORITHM_SWAP_RANGES_HPP