change 'this' pointer for structs to reference type

Denis Koroskin 2korden at gmail.com
Sun Nov 2 13:17:47 PST 2008


On Sun, 02 Nov 2008 23:03:26 +0300, Simen Kjaeraas  
<simen.kjaras at gmail.com> wrote:

> 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.
>

I'm not sure about this:

auto foo1 = new Foo();
auto i1 = foo1[42];  // what is typeof(i1)?

auto foo2 = new Foo[100];
auto i2 = foo2[42];  // what is typeof(i2)?

I expect to see Foo in both cases.



More information about the Digitalmars-d mailing list