Extended Type Design.
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Tue Mar 20 13:23:49 PDT 2007
Andrei Alexandrescu (See Website For Email) wrote:
> Derek Parnell wrote:
>> On Mon, 19 Mar 2007 22:34:13 -0700, Andrei Alexandrescu (See Website For
>> Email) wrote:
>>
>>> Tyler Knott wrote:
>>>> *const and invariant only make sense when applied to references,
>>>> otherwise they are ignored or (preferably) errors.
>>> Correct.
>>
>> Can 'const' and 'invariant' apply to structs, especially ones that
>> contain
>> references.
>>
>> struct Foo
>> {
>> char[] s;
>> char c;
>> }
>>
>> const Foo f; // Is this a mistake then?
>
> That code is fine. I should have said "const and invariant make sense
> only when applied to types that are, or contain, references". Sorry.
>
>> f.s[0] = 'a'; // okay???
>
> No.
>
>> f.s = "xyz"; // okay???
>
> Yes.
>
>> f.s = "def".dup; // okay ???
>
> Yes.
>
>> f.s.length = 1; // okay?
>
> Yes.
>
>> f.s ~= 'a'; // okay??
>
> Yes.
>
>> f.c = 'a'; // okay???
>
> Yes.
>
>> const Foo somefunc();
>> f = somefunc; // okay??
>
> Yes.
>
>> Foo someotherfunc();
>> f = someotherfunc; // okay??
>
> Yes. Non-const transforms into const no problem.
>
>
> Andrei
What?? If f is 'const', how are any of those "f.s =" assignments allowed?
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list