Don wrote:
Andrei Alexandrescu wrote:
We're entering the finale of D2 and I want to keep a short list of things that must be done and integrated in the release. It is clearly understood by all of us that there are many things that could and probably should be done.

1. Currently Walter and Don are diligently fixing the problems marked on the current manuscript.

2. User-defined operators must be revamped.

Should opIndex and opSlice be merged?
This would be simpler, and would allow multi-dimensional slicing.

Yes, please. :)


Probably the simplest way to do this would be to use fixed length arrays of length 2 for slices.
So, for example, if the indices are integers, then
opIndex(int x) { } is the 1-D index, and
opIndex(int[2] x) {} is a slice from x[0] to x[1],
which exactly corresponding to the current opSlice(x[0]..x[1]).

Since fixed-length arrays are now passed by value (yay!) this would be just as efficient as the current method. It'd be simple to implement.

Downsides: (1) Arguably not terribly intuitive.
[...]

I think this is the only way to do it, and I don't see why it's less intuitive than anything else. If it helps, you can always define

  alias size_t[2] slice_t;

(or something similar) in object.d.

  // Submatrix slice
  real opIndex(slice_t rows, slice_t cols) { ... }

Doesn't look bad at all.

-Lars

Reply via email to