opIndex() may hide opSlice()

XavierAP via Digitalmars-d digitalmars-d at puremagic.com
Fri Mar 10 08:00:38 PST 2017


On Friday, 10 March 2017 at 15:41:31 UTC, Jonathan M Davis wrote:
> On Friday, March 10, 2017 14:15:45 Nick Treleaven via 
> Digitalmars-d wrote:
>> On Friday, 10 March 2017 at 01:10:21 UTC, H. S. Teoh wrote:
>> >
>> > 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..$])?
>
> Yeah, I've never understood how it made any sense for opIndex 
> to be used for slicing, and I've never used it that way. I 
> generally forget that that change was even made precisely 
> because it makes no sense to me, whereas using opSlice for 
> slicing makes perfect sense. I always use opIndex for indexing 
> and opSlice for slicing just like they were originally designed.

I agree, the problem is that the current behavior prefers 
opIndex(), so deprecating that one would break compatibility. 
Could be done in phases then.

But this isn't really worth much bother of course.


More information about the Digitalmars-d mailing list