Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::regex: Unexpected behaviour
From: Andrew Holden (aholden_at_[hidden])
Date: 2009-07-31 09:08:00


Pascal Kesseli wrote:
Sent: Friday, July 31, 2009 6:40 AM
>
> However, changing line 18 to:
> if(regex_match(lexical_cast<string>(match[2]), match,
REPORT_DATA_ITEM)) {
>
> and thus eliminating the temporary variable tmp, results in the
following
> output:
>
> kW
> kvar
> 1090618220000
> 0008
> 15
> 1: (1.5.0)(kW)(5.5.0)(kvar)(8.5.0)(kvar)
> 1:
> 1:
>
> What might be the problem here? Am I misusing the match_results class
in
> some way?
>
> Thanks for any help and best regards
>Pascal

match_results stores iterators into the original string. The string
returned from lexical_cast goes out of scope as soon as regex_match
returns, therefore invalidating the iterators in match_results.

HTH

Andrew


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net