Boost logo

Boost :

From: John_Maddock_at_[hidden]
Date: 2001-10-20 05:29:24


> Is the following legal for regex?
>
> const char* data = ...;
> const size_t length = ...;
> boost::cmatch what
> if( boost::regex_match( std::string( data, length ), what ) {
> ...
> cout << what[ 1 ] << endl;
> }

 No that's not legal, the fact that only iterators are stored is a
deliberate design.
>
> The problem is that I pass a temporary object and AFAICS 'what' only
> stores a reference (iterator?) to the source. When accessing what[
1 ],
> the data is no longer valid. Should this be documented (I haven't
found
> anything in the docs) or should the implementation be fixed? It
seems to
> me that this is a very dangerous interface as nothing in the above
code
> looks 'suspicious'. Or am I missing something?

I've updated the docs in the cvs to make the point that iterators are
only valid for as long as the thing they point to.

I've added docs for the smatch and wsmatch typedefs that George
alluded to as well.

John Maddock


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