Question about _M_ibegin() and _M_iend()
Nathan Myers
ncm-nospam@cantrip.org
Sun Dec 9 14:44:00 GMT 2001
On Sun, Dec 09, 2001 at 06:35:08PM +0100, Paolo Carlini wrote:
> [_M_ibegin() and _M_iend()] don't call _M_leak. ...
> Could you please explain a bit what's the difference ... ?
The standard defines guarantees on the lifetimes of string iterators,
and (IIRC) of the results of data() and c_str(). Once an iterator
has been released, the _Rep it refers to must not be deallocated, or
changed via any other string that it may (earlier) have shared storage
with, and it must not come to share storage with any other string,
because the iterator may be used to change the string contents.
Certain events (assignment, resize, etc.) invalidate iterators and
allow the _Rep to go away or, anyway, to be shared again.
We use private members ibegin() and iend() internally when we don't
need such guarantees, nor want the costs they incur. In some cases
calling begin() is a good shorthand way to get them.
HTH,
Nathan Myers
ncm at cantrip dot org
More information about the Libstdc++
mailing list