All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
rotate.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Robert Rosolek
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
16 #ifndef PAAL_ROTATE_HPP
17 #define PAAL_ROTATE_HPP
19 
20 #include <boost/range/iterator.hpp>
21 #include <boost/range/join.hpp>
22 
23 #include <iterator>
24 
25 namespace paal {
26 namespace utils {
27 
37 template <class ForwardRange>
38 auto rotate(const ForwardRange& rng, range_to_diff_type_t<ForwardRange> n)
39 {
40  // TODO for some reason std::next doesn't compile under clang
41  // for boost::zip range
42  //auto const mid = std::next(std::begin(rng), n);
43  auto const mid = std::begin(rng) + n;
44  return boost::join(
45  boost::make_iterator_range(mid, std::end(rng)),
46  boost::make_iterator_range(std::begin(rng), mid)
47  );
48 }
49 
50 }
51 }
52 
53 #endif // PAAL_ROTATE_HPP
typename boost::range_difference< Range >::type range_to_diff_type_t
for given collection returns its difference type
auto rotate(const ForwardRange &rng, range_to_diff_type_t< ForwardRange > n)
returns rotated view of the given range
Definition: rotate.hpp:38