change 'this' pointer for structs to reference type

Simen Kjaeraas simen.kjaras at gmail.com
Sun Nov 2 12:03:26 PST 2008


On Sun, 02 Nov 2008 20:26:23 +0100, Moritz Warning <moritzwarning at web.de>  
wrote:

> On Sun, 02 Nov 2008 00:01:24 -0700, Walter Bright wrote:
>
>> Andrei suggested this change, and I think it is a great idea. D ought to
>> be moving away from pointers for routine work, and this would make a lot
>> of sense.
>>
>> It would entail some changes to user code, mostly when dealing with the
>> opCmp and opEquals member functions. The function signatures for them
>> would be changed to opCmp(ref const S).
>
> It's not clear to me what the effect would be on the usage.
>
> struct Foo
> {
>    int OpIndex(size_t){}
> }
>
> Foo foo = new Foo();
> foo[42];
>
> Could we do call opIndex now because this of Foo is a reference?
> It would be nice.
> But it might be "ref Foo foo = new Foo();" because it bites "Foo foo;"
> otherwise.
>
> Or am I off the track?

You're somewhat off track. Foo foo = new Foo(); will not compile, as
new Foo would still return a Foo*. auto foo = new Foo(); foo[42]; would
work, though.

-- 
Simen



More information about the Digitalmars-d mailing list