Hmm ... I thought I understood regular expressions, and I thought I understood iterators, but the implementation of the C ++ 11 regular expression puzzled me ...
One area I don’t understand: after reading about regex token iterators , I came across the following code example:
#include <fstream>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <regex>
int main()
{
std::string text = "Quick brown fox.";
std::regex ws_re("\\s+");
std::copy( std::sregex_token_iterator(text.begin(), text.end(), ws_re, -1),
std::sregex_token_iterator(),
std::ostream_iterator<std::string>(std::cout, "\n"));
...
}
I do not understand how the following conclusion:
Quick
brown
fox.
created by the std :: copy () function above. I don't see the loop, so I'm puzzled by how the iteration happens. Or else, how is more than one line of output generated?
source
share