Created
July 12, 2017 08:54
-
-
Save taeguk/3f440af89d71b2fc5412a7fe7b57d4d9 to your computer and use it in GitHub Desktop.
my_std_rotate.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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