rotate.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright Neil Groves 2009. Use, modification and
  2. // distribution is subject to the Boost Software License, Version
  3. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. //
  7. // For more information, see http://www.boost.org/libs/range/
  8. //
  9. #ifndef BOOST_RANGE_ALGORITHM_ROTATE_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_ROTATE_HPP_INCLUDED
  11. #include <boost/concept_check.hpp>
  12. #include <boost/range/begin.hpp>
  13. #include <boost/range/end.hpp>
  14. #include <boost/range/concepts.hpp>
  15. #include <algorithm>
  16. namespace boost
  17. {
  18. namespace range
  19. {
  20. /// \brief template function rotate
  21. ///
  22. /// range-based version of the rotate std algorithm
  23. ///
  24. /// \pre Rng meets the requirements for a Forward range
  25. template<class ForwardRange>
  26. inline ForwardRange& rotate(ForwardRange& rng,
  27. BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type middle)
  28. {
  29. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  30. std::rotate(boost::begin(rng), middle, boost::end(rng));
  31. return rng;
  32. }
  33. /// \overload
  34. template<class ForwardRange>
  35. inline const ForwardRange& rotate(const ForwardRange& rng,
  36. BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type middle)
  37. {
  38. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  39. std::rotate(boost::begin(rng), middle, boost::end(rng));
  40. return rng;
  41. }
  42. } // namespace range
  43. using range::rotate;
  44. } // namespace boost
  45. #endif // include guard