Skip to content

Instantly share code, notes, and snippets.

@taeguk
Created July 12, 2017 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taeguk/3f440af89d71b2fc5412a7fe7b57d4d9 to your computer and use it in GitHub Desktop.
Save taeguk/3f440af89d71b2fc5412a7fe7b57d4d9 to your computer and use it in GitHub Desktop.
my_std_rotate.cpp
// VS http://en.cppreference.com/w/cpp/algorithm/rotate
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 next = n_first;
do {
std::iter_swap(first++, next++);
if (first == n_first) n_first = next;
}
while (next != last);
ForwardIt ret = first;
while (n_first != last) {
next = n_first;
do {
std::iter_swap(first++, next++);
if (first == n_first) n_first = next;
}
while (next != last);
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment