change 'this' pointer for structs to reference type

Simen Kjaeraas simen.kjaras at gmail.com
Mon Nov 3 01:22:04 PST 2008


On Mon, 03 Nov 2008 00:15:48 +0100, Moritz Warning <moritzwarning at web.de>  
wrote:

> On Mon, 03 Nov 2008 00:17:47 +0300, Denis Koroskin wrote:
>
>> 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){}
>>>> }
>>>>
> [..]
>>>
>>>
>> 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.
>
> typeof(il) have to be int since opIndex returns int.

'fraid not. foo1 would be of type Foo*, so foo1[42] would return
cast(Foo)(*(foo1 + 42 * Foo.sizeof)). So in both cases, the return value  
would
be of type Foo.

-- 
Simen



More information about the Digitalmars-d mailing list