opIndex() may hide opSlice()

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Fri Mar 10 06:15:45 PST 2017


On Friday, 10 March 2017 at 01:10:21 UTC, H. S. Teoh wrote:
> On Fri, Mar 10, 2017 at 01:07:33AM +0000, XavierAP via 
> Digitalmars-d wrote:
>> The web reference tersely says under its *Slice* Operator 
>> Overloading chapter [1]: "To overload a[], simply define 
>> opIndex with no parameters."
>> 
>> Should not the overload of opSlice() with no arguments be 
>> deprecated?
>> Am I missing something?
>
> Using opSlice() for slicing (i.e., arr[]) is old, 
> backward-compatible
> behaviour.

This seems non-intuitive to me (at least for single dimension 
containers) - when you see var[], do you think var is being 
indexed or do you think var is being sliced like an array 
(equivalent to var[0..$])?

Also deprecating nullary opSlice() would work against defining 
opSlice(int low = 0, int high = length).


More information about the Digitalmars-d mailing list