|
Boost : |
Subject: Re: [boost] [string] proposal
From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2011-01-21 14:40:44
On Sat, Jan 22, 2011 at 3:18 AM, Dave Abrahams <dave_at_[hidden]> wrote:
> At Sat, 22 Jan 2011 01:56:36 +0800,
> Dean Michael Berris wrote:
>>
>> No changing arbitrary content in the string. Concatenation is a
>> process of creating new strings.
>
> But you're allowing assignment. Â That's not acting "as if it's const,
> with no way to modify the string"
>
Unless you frame assignment in terms of a "move".
x = "This is the original";
x = "Not anymore";
What's happening here is that you're really making x refer to a
different string. In essence, x is what you might call a proxy. You
can change what the proxy refers to, but what it refers to you cannot
change -- if that makes any sense. If you're reading or dealing with
x, basically you're dealing with the proxy.
So when you're doing concatenation, what's really happening is you're
building a new string and making the proxy refer to that new string.
x = "Hello,";
x = x ^ " World!";
Note this doesn't violate the value semantics of the object much like
how pointers provide value semantics (because they are values).
-- Dean Michael Berris about.me/deanberris
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk