Boost logo

Boost :

From: Maxim Yegorushkin (e-maxim_at_[hidden])
Date: 2004-09-18 19:27:18


Jonathan Turkanis <technews_at_[hidden]> wrote:

>> Jonathan Turkanis wrote:
>> > [...]
>> > 2. I don't understand the following statement:
>> >
>> > Unlike std::basic_string<>, empty string object references empty
>> c-style
>> > string "".
>>
>> I think this means that if the string contains a charT*, it will never
>> be null (but rather point to a special empty string object).

That is true. I can't clearly state which benefits it provides, but it
seemed to me that it would be more natural for an empty string to be the
same as "".

[]

>> > 3. What are the semantics of
>> >
>> > std::string str("abc");
>> > h(boost::cref(str));
>>
>> Without looking at the code, I would expect that the const_string<>
>> would share a representation with str, thus implying that it had
>> better not outlive str.

That is also true. By default the string allocates and copies its
argument, but it can be forced not to do so by wrapping the argument with
boost:cref() call.

> And that str must not be modified during its lifetime, I guess.

This is what the string is all about - using its interface it is
impossible to inadvertently modify the string.

-- 
Maxim Yegorushkin

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