iterators again
David B. Held
dheld at codelogicconsulting.com
Sat Jun 2 12:44:41 PDT 2007
Bruno Medeiros wrote:
> Walter Bright wrote:
>> [...]
>> It'll be an error, since there's no way to deduce the type of foo. But
>> let's rewrite it as:
>> final int foo;
>> auto fooptr = &foo;
>> Since foo cannot change its value, then fooptr must be an
>> invariant(int)*.
>
> [...]
> Second, let's change the first example, let's have a Foo instead of an int:
> final Foo foo;
> auto fooptr = &foo;
> What would be the type of fooptr? Would it also be invariant(Foo)* ?
> What would be the type of *fooptr? Would it be invariant(Foo) ?
> If so, would that mean that the following would not be allowed:
> (*fooptr).membervar = 42 ;
> even though this is:
> foo.membervar = 42;
> ?
I think that Walter's scenario must type to const(int)*, for
consistency, even though const(int)* and invariant(int)* are equivalent,
given that int is an elementary value type. This leads to the proper
conclusion that typeof(fooptr) == const(Foo)*, typeof(*fooptr) ==
const(Foo).
Dave
More information about the Digitalmars-d
mailing list