Created
December 9, 2015 13:37
-
-
Save thiagomg/07b7ace3c40be2865c67 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
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