Boost logo

Boost :

Subject: Re: [boost] RFC: interest in Unicode codecs?
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-07-21 09:35:29


Phil Endecott wrote:
> Stewart, Robert wrote:
> > Sebastian Redl wrote:
> >> Phil Endecott wrote:
> >> >
> >> > Here is an outline of a zero-overhead wrapper for std::string
> >> > that I hope guarantees that *end() == 0:
> >> >
> >> > struct string_with_zero_beyond_end: std::string {
> >> > typedef const char* const_iterator;
> >> > const_iterator begin() const { return c_str(); }
> >> > const_iterator end() const { return c_str() + length(); }
> >> > };
> >>
> >> Not zero-overhead if the string implementation is one (of the
> >> non-existent ones) that doesn't store the NUL internally.
>
> Is c_str() allowed to be > O(1) ?

Yes, since the entirety of C++98/03's requirements levied against c_str() are shown here:

>From 21.3/5: It can invalidate outstanding iterators, references, and pointers.

>From 21.3.6:

"1 Returns: A pointer to the initial element of an array of length size() + 1 whose first size() elements equal the corresponding elements of the string controlled by *this and whose last element is a null character specified by charT().

2 Requires: The program shall not alter any of the values stored in the array. Nor shall the program treat the returned value as a valid pointer value after any subsequent call to a nonconst member function of the class basic_string that designates the same object as this."

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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