What algorithm is used for std::rotate in this example?

Viewed 129

I'm trying to find out the name for an algorithm which is basically the one used on cppreference for std::rotate. This is the code:

template<class ForwardIt>
ForwardIt rotate(ForwardIt first, ForwardIt n_first, ForwardIt last)
{
   if(first == n_first) return last;
   if(n_first == last) return first;
 
   ForwardIt read      = n_first;
   ForwardIt write     = first;
   ForwardIt next_read = first; // read position for when "read" hits "last"
 
   while(read != last) {
      if(write == next_read) next_read = read; // track where "first" went
      std::iter_swap(write++, read++);
   }
 
   // rotate the remaining sequence into place
   (rotate)(write, next_read, last);
   return write;
}

(Reference at https://en.cppreference.com/w/cpp/algorithm/rotate)

I thought it was the Juggling algorithm, but I don't see anything related to the greatest common divisor, so I suppose it's not that?

0 Answers
Related