Skip to content

Instantly share code, notes, and snippets.

@thiagomg
Created December 9, 2015 13:37
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/07b7ace3c40be2865c67 to your computer and use it in GitHub Desktop.
Save thiagomg/07b7ace3c40be2865c67 to your computer and use it in GitHub Desktop.
Legibilidade com C++14 - get_numeric
template<class OutputIterator, class ValueType>
struct numerical_appender {
numerical_appender(OutputIterator it) : _it(it) { }
void operator()(const ValueType c) {
if( c >= '0' && c <= '9' ) {
*_it = c;
_it++;
}
}
private:
OutputIterator _it;
};
template<class T>
void get_numeric(const T &input, T &output)
{
typedef std::back_insert_iterator<T> it_type;
it_type it = std::back_inserter(output);
numerical_appender<it_type, typename T::value_type> appender(it);
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