opSlice Bug?

Ali Çehreli acehreli at yahoo.com
Thu Nov 29 09:00:40 PST 2012


On 11/29/2012 08:50 AM, Namespace wrote:
> On Thursday, 29 November 2012 at 16:46:45 UTC, Ali Çehreli wrote:
>> On 11/29/2012 08:15 AM, Namespace wrote:
>>> Why I have to write
>>> arr2[] += arr[][]
>>> instead of
>>> arr2[] += arr[]
>>> ? Bug or 'feature'? :P
>>>
>>> Code:
>>> http://dpaste.dzfl.pl/4c732f4c
>>
>> opSplice, eh? Is that another undocumented feature or one that has
>> been deprecated?
>>
>> Ali
>
> http://dlang.org/operatoroverloading.html#Slice

Thanks. I really did read it as opS_p_lice, found a few references on 
dlang.org, none on any spec page and got a little frustrated. I did not 
realize that I had clearly misread it.

I had even written some notes about opSlice:

   http://ddili.org/ders/d.en/operator_overloading.html

Apparently I had thought that it better returned a special type:

struct Range
{
     // ...
}

struct Container
{
     // For the object[] syntax
     Range opSlice()
     {
         Range allElements;
         // ... must provide access to all elements ...
         return allElements;
     }

/* ... */
}

Ali


More information about the Digitalmars-d-learn mailing list