1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2014 Roshan <thisisroshansmail@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_ROTATE_HPP
12 #define BOOST_COMPUTE_ALGORITHM_ROTATE_HPP
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/algorithm/copy.hpp>
16 #include <boost/compute/container/vector.hpp>
21 /// Performs left rotation such that element at \p n_first comes to the
24 /// Space complexity: \Omega(distance(\p first, \p last))
26 /// \see rotate_copy()
27 template<class InputIterator>
28 inline void rotate(InputIterator first,
29 InputIterator n_first,
31 command_queue &queue = system::default_queue())
33 //Handle trivial cases
34 if (n_first==first || n_first==last)
40 typedef typename std::iterator_traits<InputIterator>::value_type T;
42 size_t count = detail::iterator_range_size(first, n_first);
43 size_t count2 = detail::iterator_range_size(first, last);
45 const context &context = queue.get_context();
46 vector<T> temp(count2, context);
47 ::boost::compute::copy(first, last, temp.begin(), queue);
49 ::boost::compute::copy(temp.begin()+count, temp.end(), first, queue);
50 ::boost::compute::copy(temp.begin(), temp.begin()+count, last-count, queue);
53 } //end compute namespace
54 } //end boost namespace
56 #endif // BOOST_COMPUTE_ALGORITHM_ROTATE_HPP