Skip to content

Instantly share code, notes, and snippets.

@thiagomg
Created December 9, 2015 13:36
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 thiagomg/29f45db0e8fc0ea6166e to your computer and use it in GitHub Desktop.
Save thiagomg/29f45db0e8fc0ea6166e to your computer and use it in GitHub Desktop.
Legibilidade com C++14 - get_numeric
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