Currently, it is not possible to use extended for-loops with stuff like std::sregex_iterator, because there is no
.begin()/
.end() pair and no
std::begin/
std::end pair for
std::sregex_iterator -- adding an overload for
std::sregex_iterator to the
std-namespace is trivial and doing so will allow using them in extended for-loops.
I'm already doing this in production code and so far, have found no issues with it.
My implementation is fairly simple: std::begin(std::sregex_iterator&) returns the argument and std::end(std::sregex_iterator&) return a default constructed std::sregex_iterator:
namespace std {
auto end(std::sregex_iterator& ) -> std::sregex_iterator& {
static std::sregex_iterator end_of_sequence_iterator;
return end_of_sequence_iterator;
}
auto begin(std::sregex_iterator& b) -> std::sregex_iterator& {
return b;
}
}