[phobos] phobos commit, revision 2181
Andrei Alexandrescu
andrei at erdani.com
Fri Nov 19 13:38:26 PST 2010
On 11/19/10 1:20 PM, spir wrote:
> On Fri, 19 Nov 2010 09:18:47 -0800
> Andrei Alexandrescu<andrei at erdani.com> wrote:
>
>> On 11/19/10 2:22 AM, spir wrote:
>>> Hum, is this really a transgression of const's promise? Each object's .name fields remains unchanged as expected. Rather only the symbolic relations (var-id<--> object) change. It's another kind of change.
>>> Here, the 2 facts that the fields are called 'name' and that they hold values equal to var-ids, commonly called 'name' as well, just introduce confusion.
>>> What about this, is it also inacceptable?
>>>
>>> struct S
>>> {
>>> const uint code;
>>> }
>>> auto a = S(1); // a<--> obj1 (code:1)
>>> auto b = S(1); // b<--> obj2 (code:2)
>>>
>>> swap(a, b);
>>> assert(a.code == 2); // a<--> obj2 (code:2)
>>> assert(b.code == 1); // b<--> obj1 (code:1)
>>
>> A const field is expected to always stay the same after being set.
>
> The field here is left unchanged.
If a constructor establishes the const field to have e.g. value 1, it
would be quite surprising if that field actually becomes 2.
Andrei
More information about the phobos
mailing list