Boost logo

Boost :

Subject: Re: [boost] RFC: interest in Unicode codecs?
From: Howard Hinnant (howard.hinnant_at_[hidden])
Date: 2009-07-23 10:09:19


On Jul 21, 2009, at 9:54 AM, Thorsten Ottosen wrote:

> Sebastian Redl skrev:
>> Phil Endecott wrote:
>>> Is c_str() allowed to be > O(1) ?
>> Yes. In particular, this implementation is valid:
>> template <...>
>> class basic_string
>> {
>> Ch *real_data;
>> mutable Ch *cstr_data;
>> // ...
>> public:
>> const Ch *c_str() const {
>> if (!cstr_data) {
>> cstr_data = allocate(size() + 1);
>> copy(cstr_data, size());
>> cstr_data[size()] = 0;
>> }
>> return cstr_data;
>> }
>> void any_modifying_function() {
>> if(cstr_data) {
>> deallocate(cstr_data);
>> cstr_data = 0;
>> }
>> }
>> };
>
> But does *any* implementation actually do that? The problem is AFAIK
> that str[size] is valid when str is a const object.

Fwiw, the C++0X string will (probably) require the trailing null for
non-const strings too:

http://home.roadrunner.com/~hinnant/issue_review/lwg-active.html#876

(see A 2)

And the committee knows of no implementations this will break.

-Howard


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