Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

If string::c_str() doesn't invalidate iterators ...

23 views
Skip to first unread message

Kli-Kla-Klawitter

unread,
Jun 24, 2021, 10:51:03 AM6/24/21
to
If string::c_str() doesn't invalidate iterators, I could access
str[str.length()] safely myself even it's outside the bounds
because the storage for the zero-termination must be pre-allocated
to terminate the string in-place. Cooooooooooooooool!

Öö Tiib

unread,
Jun 24, 2021, 11:27:52 AM6/24/21
to
There are no such strange logic needed. The str[str.length()] is
required to return reference to null character after last character
of string. Modifying that null character using the reference is
undefined behavior.

Alf P. Steinbach

unread,
Jun 24, 2021, 11:37:25 AM6/24/21
to
KKK has probably read some C++03 discussion.

In C++03 the terminating zero in the buffer was only guaranteed via the
`const` accessors.

The guarantees were revamped for C++11 allegedly for thread safety
(which I regard as a whole load of bollocks), but incidentally so that a
design level error in the C++03 COW support was removed -- with that
bathwater also containing the baby COW, but hey, no pain no gain.


- Alf
0 new messages