Dear all:
How does the default of constructor of std::regex_iterator "know" where the end address of the sregex match is ?
For example in the code below:
M_end is constructed independently from the regex and the string. So how can the for loop end at the right position ?
Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14
std::regex pattern (R"(([-+]?[0-9]*\.?[0-9]+([eE\^][+-]?[0-9]+)?)\b)");
for ( int i = 0; i < number_of_particles; ++i)
{
std::getline ( file,line );
auto M_begin = std::sregex_iterator(line.begin(), line.end(), pattern);
auto M_end = std::sregex_iterator();
int j=0;
for ( std::sregex_iterator iter = M_begin ; iter != M_end; ++iter )
{
std::smatch match = *iter;
q_i[j+i*dim] = atof (match.str().c_str());
++j;
}
}
A special value of regex_iterator is used to indicate an end-of-sequence. This iterator should not be dereferenced. Its value is the same for all end-of-sequence regex_iterator objects of the same type, no matter the sequence being iterated by each.
I already read this but didn't got it then. But I think I understood it now: My error was to think of iterators as pointers. Basically M_begin will become an end_of_sequence iterator and the for loop ends. So there is no direct comparison of addresses pointed to ...
Thanks for making me read it again :-D