]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/swap_ranges.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / compute / algorithm / swap_ranges.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
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
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #ifndef BOOST_COMPUTE_ALGORITHM_SWAP_RANGES_HPP
12 #define BOOST_COMPUTE_ALGORITHM_SWAP_RANGES_HPP
13
14 #include <boost/static_assert.hpp>
15
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>
21
22 namespace boost {
23 namespace compute {
24
25 /// Swaps the elements in the range [\p first1, \p last1) with the
26 /// elements in the range beginning at \p first2.
27 ///
28 /// Space complexity: \Omega(distance(\p first1, \p last1))
29 template<class Iterator1, class Iterator2>
30 inline Iterator2 swap_ranges(Iterator1 first1,
31 Iterator1 last1,
32 Iterator2 first2,
33 command_queue &queue = system::default_queue())
34 {
35 BOOST_STATIC_ASSERT(is_device_iterator<Iterator1>::value);
36 BOOST_STATIC_ASSERT(is_device_iterator<Iterator2>::value);
37
38 typedef typename std::iterator_traits<Iterator1>::value_type value_type;
39
40 Iterator2 last2 = first2 + std::distance(first1, last1);
41
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);
45
46 return last2;
47 }
48
49 } // end compute namespace
50 } // end boost namespace
51
52 #endif // BOOST_COMPUTE_ALGORITHM_SWAP_RANGES_HPP