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 /// \see rotate_copy()
25 template<class InputIterator>
26 inline void rotate(InputIterator first,
27 InputIterator n_first,
29 command_queue &queue = system::default_queue())
31 //Handle trivial cases
32 if (n_first==first || n_first==last)
38 typedef typename std::iterator_traits<InputIterator>::value_type T;
40 size_t count = detail::iterator_range_size(first, n_first);
41 size_t count2 = detail::iterator_range_size(first, last);
43 const context &context = queue.get_context();
44 vector<T> temp(count2, context);
45 ::boost::compute::copy(first, last, temp.begin(), queue);
47 ::boost::compute::copy(temp.begin()+count, temp.end(), first, queue);
48 ::boost::compute::copy(temp.begin(), temp.begin()+count, last-count, queue);
51 } //end compute namespace
52 } //end boost namespace
54 #endif // BOOST_COMPUTE_ALGORITHM_ROTATE_HPP