I have an issue accessing sub-matches from boost::match_results class. When I examine the program in debugger, match_results::m_subs array contains exactly what I expect:
- [0] Is the full match.
- [1] And further are submatches. They match exactly as expected.
However, when I try to acces the submatches using operator[] and index of the submatch starting with 1, I don't get what I want. The reason is hidden in boost source:
const_reference operator[](int sub) const
{
if(m_is_singular && m_subs.empty())
raise_logic_error();
sub += 2; //< WTF?
if(sub < (int)m_subs.size() && (sub >= 0))
{
return m_subs[sub];
}
return m_null;
}
I'm totally confused about this. The documentation says I just access n-th submatch using [n], but in code, there's this weird offset everywhere.
Please tell me I'm not insane :)
Checked boost versions: 1.54 and 1.53