opIndex() may hide opSlice()

jmh530 via Digitalmars-d digitalmars-d at puremagic.com
Fri Mar 10 12:21:11 PST 2017


On Friday, 10 March 2017 at 18:43:43 UTC, H. S. Teoh wrote:
>
> So probably we should leave it the way it is (and perhaps 
> clarify that in the spec), as deprecating the "old" use of 
> opSlice in the 1-dimensional case would cause problems.
>

ndslice just recently added an indexed function
http://docs.algorithm.dlang.io/latest/mir_ndslice_topology.html#.indexed
that is like slicing based on some index. Other languages have 
something similar.

However, it's not something that's built-in in D. Thus, given the 
indexed example:

auto source = [1, 2, 3, 4, 5];
auto indexes = [4, 3, 1, 2, 0, 4].sliced;
auto ind = source.indexed(indexes);

there's way to instead write

auto source = [1, 2, 3, 4, 5];
auto indexes = [4, 3, 1, 2, 0, 4].sliced;
auto ind = source[indexes];

So to me, there does seem scope for some changes, even if they 
aren't the changes you mentioned in your post.



More information about the Digitalmars-d mailing list