Boost logo

Boost :

From: Pavol Droba (droba_at_[hidden])
Date: 2004-04-07 03:34:40


On Wed, Apr 07, 2004 at 03:37:46AM -0400, David Abrahams wrote:
> Pavol Droba <droba_at_[hidden]> writes:
>
> > On Tue, Apr 06, 2004 at 08:33:56PM -0400, David Abrahams wrote:
> >> "Eric Niebler" <eric_at_[hidden]> writes:
> >>
> >> > David Abrahams wrote:
> >> >> Pavol Droba <droba_at_[hidden]> writes:
> >> >>>On Tue, Apr 06, 2004 at 02:43:20PM -0400, David Abrahams wrote:
> >> >>>>> What would be the advantage? User can write iterator_range
> >> >>>>> res=regex_maxch(...);
> >> >>>>
> >> >>>>Doesn't the match object get destroyed here, thereby invalidating the
> >> >>>>iterators?
> >> >>>>
> >> >>>Not really as far as I know. Iterators are bound to the collection that is being searched,
> >> >>>not to the match itself. Therfore, they validity should not be bound the lifetime
> >> >>>of them match. They will be copied to the iterarator_range.
> >> >> The match object *is* the collection (of submatches) being searched.
> >> >>
> >> >
> >> >
> >> > A sub-match is just a glorified pair of iterators. The iterators refer
> >> > to the sequence being searched, which has a lifetime independent of
> >> > the match object. There is no risk of iterator invalidation here.
> >>
> >> I'm not worried about submatch's iterators over the original input
> >> sequence, but about the match_results's iterators over submatches.
> >>
> >
> > These are destroyed and forgotten. That's the idea of the example.
> > If you are interested only in the success/failure of the search operation, or
> > you want to know which part of sequence has been matched, then you don't need
> > full match_results. Those two iterators (contained in the iterator_range) are
> > more then sufficient, and you don't need to pay an extra price implied by
> > match_results.
> >
> > Maybe I got it wrong, but the discussion before seemed to deal with a problem
> > like this.
>
> Maybe I got it wrong; I want to be able to look at the 2nd
> submatch when the match succeeded. If all I get is an iterator the
> whole substring that matched, it's of no use to me.
>
Sorry, I have overlooked your need for the second match. Then the whole story I have
written is probably of a little use to you.

You can of course apply the same idea for submatches. I.e to write something like this:

iterator_range res=regex_search(....)[2]

Anyway, this would work if you need only a specific part of the match, not if you need to
play with whole match_results object.

Regards,

Pavol


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk