Boost logo

Boost :

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


Sebastian Redl wrote:
> Phil Endecott wrote:
> > Eric Niebler wrote:
> >> I believe that as of C++03, std::string is required to have
> >> contiguous storage. The null-termination is another thing.
> >> The only guarantee is that the char* returned by c_str() is
> >> required to be null terminated. No such guarantee is made
> >> for the sequence traversed by std::string's iterators.
> >> Dereferencing the end iterator is verboten.
> >
> > 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.

Worse: you'd be returning iterators to what may well be a
temporary array of characters. The result of calling c_str()
need not refer to the internal storage of the string.

There's also the issue of deriving from a concrete class so that
slicing will revert to std::string::begin()/end().

Then there's also the little problem of std::string implementations
that don't use raw pointers for iterators, particularly those in
a checked STL.

_____
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