General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
499 B

пре 4 година
пре 4 година
  1. #pragma once
  2. #include "gp/algorithm/move.hpp"
  3. namespace gp {
  4. template<typename iterator>
  5. iterator rotate(iterator first, iterator new_first, iterator last)
  6. {
  7. if(first == new_first) return last;
  8. if(new_first == last) return first;
  9. iterator in = new_first;
  10. iterator out = first;
  11. iterator mv = first;
  12. while(in != last) {
  13. if(out == mv) mv = in;
  14. gp::swap((*out++), (*in++));
  15. }
  16. // rotate the remaining sequence into place
  17. (rotate)(out, mv, last);
  18. return out;
  19. }
  20. }