Created
December 28, 2019 23:58
-
-
Save bolry/eb5bc65e1b5a14f25422e81880a0aced to your computer and use it in GitHub Desktop.
reverse_if and reverseOnlyLetters
This file contains hidden or 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
#include <algorithm> | |
#include <boost/iterator/filter_iterator.hpp> | |
template <class Iter, class Predicate> | |
void reverse_if(Iter first, Iter last, Predicate pred) { | |
std::reverse(boost::make_filter_iterator(pred, first, last), | |
boost::make_filter_iterator(pred, last, last)); | |
} | |
#include <locale> | |
void reverseOnlyLetters(std::string &s) { | |
reverse_if(s.begin(), s.end(), | |
[](char c) { return std::isalpha(c, std::locale{}); }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment