Created
December 9, 2015 13:36
-
-
Save thiagomg/29f45db0e8fc0ea6166e to your computer and use it in GitHub Desktop.
Legibilidade com C++14 - get_numeric
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
struct numerical_appender { | |
numerical_appender(std::string &buf) : _buf(buf) { } | |
void operator()(const char c) { | |
if( c >= '0' && c <= '9' ) _buf.push_back(c); | |
} | |
private: | |
std::string &_buf; | |
}; | |
void get_numeric(const std::string &input, std::string &output) | |
{ | |
numerical_appender appender(output); | |
std::for_each(input.begin(), input.end(), appender); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment