opIndex vs. opSlice for empty slices

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 22 07:30:50 PDT 2015


On 5/22/15 1:49 AM, weaselcat wrote:
> On Friday, 22 May 2015 at 05:47:28 UTC, Mike Parker wrote:
>> I've always used opSlice to produce empty slices, but having recently
>> read the documentation at [1], I see this:
>>
>> "To overload a[], simply define opIndex with no parameters:"
>>
>> And no mention that opSlice can fill the same role. Am I right to
>> infer that we should prefer opIndex over opSlice for this? If so,
>> what's the rationale?
>>
>>
>> [1] http://dlang.org/operatoroverloading.html#slice
>
> http://forum.dlang.org/thread/luadir$t0g$1@digitalmars.com#post-luadir:24t0g:241:40digitalmars.com
>

This is news to me, and very cool!

-Steve


More information about the Digitalmars-d-learn mailing list