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/compute/system.hpp>
15 #include <boost/compute/command_queue.hpp>
16 #include <boost/compute/algorithm/copy.hpp>
17 #include <boost/compute/container/vector.hpp>
22 /// Swaps the elements in the range [\p first1, \p last1) with the
23 /// elements in the range beginning at \p first2.
24 template<class Iterator1, class Iterator2>
25 inline Iterator2 swap_ranges(Iterator1 first1,
28 command_queue &queue = system::default_queue())
30 typedef typename std::iterator_traits<Iterator1>::value_type value_type;
32 Iterator2 last2 = first2 + std::distance(first1, last1);
34 ::boost::compute::vector<value_type> tmp(first1, last1, queue);
35 ::boost::compute::copy(first2, last2, first1, queue);
36 ::boost::compute::copy(tmp.begin(), tmp.end(), first2, queue);
41 } // end compute namespace
42 } // end boost namespace
44 #endif // BOOST_COMPUTE_ALGORITHM_SWAP_RANGES_HPP