Skip to content

Instantly share code, notes, and snippets.

@GamePad64
Created October 28, 2016 09:16
Show Gist options
  • Save GamePad64/c8c66992e8586eef4aca870f5596210f to your computer and use it in GitHub Desktop.
Save GamePad64/c8c66992e8586eef4aca870f5596210f to your computer and use it in GitHub Desktop.
#include <algorithm>
template<typename _Iterator>
void reverse_wordwise_inplace(_Iterator first, _Iterator second) {
std::reverse(first, second);
_Iterator first_w = first;
_Iterator second_w = first;
do {
second_w = std::find(first_w, second, ' ');
std::reverse(first_w, second_w);
if(second_w != second)
first_w = ++second_w;
} while(second_w != second);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment