any news on const/invariant?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Nov 26 15:26:56 PST 2007
"Walter Bright" wrote
> Derek Parnell wrote:
>> On Mon, 26 Nov 2007 14:11:25 -0800, Walter Bright wrote:
>>> 2) no more 'head const' or 'tail const', it's all just 'const'
>>
>> Does that mean that if X is const then neither the bits in X and the bits
>> referenced by X can be modified (though the X symbol)?
>
> Const and invariant are transitive. C++ const is not transitive, leading
> to programmers establishing a *convention* for transitive const. But it
> being an unenforced convention means it is not reliable.
Before, I could declare an array of const characters. Essentially, the
array structure could be modified, but the characters pointed to by the
array could not.
i.e.
const(char)[] myString = "hello";
However, in this case, I could slice my string like so
myString = myString[0..4] // set to "hell"
The way you are talking this is no longer possible? Because now I can only
have a fully const array which means you cannot change the pointer in the
array?
Just trying to clarify :)
-Steve
More information about the Digitalmars-d
mailing list