Const sucks
Walter Bright
newshound1 at digitalmars.com
Mon Sep 10 15:22:23 PDT 2007
Derek Parnell wrote:
> Remind me again what the difference between 'const' and 'invariant'
> is.
'const' means a I can't change it (but someone else can, such as someone
in a different thread). 'invariant' means nuttin' can change it, not
no-how, not no-way.
> What do these below mean ...
>
> const int (* p)
syntax error
> const int *(p)
syntax error
> const int (*) p
syntax error
Imagine if const were a template called Const, and we used that template
to form a new type that was const of the old type. We'd invoke it like:
Const!(T) t;
Now, just s/Const!/const/, and the syntax should make sense.
>> o tail const of a struct would have to be done by making the
>> struct a template:
>>
>> struct S(T) { T member; } S!(int) // tail mutable S!(const(int))
>> // tail const
>
> But most structs contain multiple members, and usually of different
> types.
That's up to the struct designer.
More information about the Digitalmars-d
mailing list