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_SWAP_RANGES_HPP
12 #define BOOST_COMPUTE_ALGORITHM_SWAP_RANGES_HPP
14 #include <boost/static_assert.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/container/vector.hpp>
20 #include <boost/compute/type_traits/is_device_iterator.hpp>
25 /// Swaps the elements in the range [\p first1, \p last1) with the
26 /// elements in the range beginning at \p first2.
28 /// Space complexity: \Omega(distance(\p first1, \p last1))
29 template<class Iterator1, class Iterator2>
30 inline Iterator2 swap_ranges(Iterator1 first1,
33 command_queue &queue = system::default_queue())
35 BOOST_STATIC_ASSERT(is_device_iterator<Iterator1>::value);
36 BOOST_STATIC_ASSERT(is_device_iterator<Iterator2>::value);
38 typedef typename std::iterator_traits<Iterator1>::value_type value_type;
40 Iterator2 last2 = first2 + std::distance(first1, last1);
42 ::boost::compute::vector<value_type> tmp(first1, last1, queue);
43 ::boost::compute::copy(first2, last2, first1, queue);
44 ::boost::compute::copy(tmp.begin(), tmp.end(), first2, queue);
49 } // end compute namespace
50 } // end boost namespace
52 #endif // BOOST_COMPUTE_ALGORITHM_SWAP_RANGES_HPP