Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-12-05 16:31:33

Herve Bronnimann:

> On Wednesday, December 05, 2007, at 12:30PM, "Peter Dimov"
> <pdimov_at_[hidden]> wrote:
>>The standard doesn't guarantee that a std::string is a contiguous array,
>>all existing implementations are. You can use &s[0] and take the risk, or
>>you can prefer dispatching on whether s.begin() returns a pointer.
> Peter: Section 21.3.1 [string.require] paragraph 3, page 578, of the
> current working draft:
> The char-like objects in a basic_string object shall be stored
> contiguously. That is, for any basic_string object s,
> the identity &*(s.begin() + n) == &*s.begin() + n shall hold for all
> values of n such that 0 <= n < s.size().
> Isn't that what Robert is asking for? Is this a new requirement (i.e.,
> not in C++03)? Indeed, I can't see it in C++03.

I think that it's new for C++0x, but even so, this requirement is a strong
indication that every std::string is already contiguous. So using &s[0] or
&*s.begin() instead of const_cast'ing data() would definitely be a step

Boost list run by bdawes at, gregod at, cpdaniel at, john at