Rather than crashing in match_results::format() when a reference to a
marked subexpression is out of range, format the subexpression as
empty (i.e., replace it with an empty string).
The standard doesn't require that marked subexpression references are
valid (the only preconditions are that ready() == true and that Out is
an output iterator), so the implementation shouldn't segfault on
out-of-range marked subexpressions. The most user-friendly behaviour
(and the easiest to implement) is to treat them as "null" sub-matches.
Another option that I rejected is to leave them un-substituted.
I'm not sure about my choice of where to put the tests. I considered
duplicating them across all four form*.pass.cpp, but thought I'd get
some feedback first.
A better idea.
Replace this code:
with:
match_results::operator[] already has the logic to do something with out of range indexes.