[Proposal] Additional operator overloadings for multidimentional indexing and slicing

filgood filgood at somewhere.com
Fri Jun 1 01:08:34 PDT 2012


This would be very cool indeed!

+1 from me.

On 01/06/2012 02:57, kenji hara wrote:
> I'd like to propose a new language feature to D community.
>
> I've opened a enhancement issue half a year ago.
>
>    Issue 6798 - Integrate overloadings for multidimentional indexing and slicing
>    http://d.puremagic.com/issues/show_bug.cgi?id=6798
>
> And, a pull request for implementing it is now available.
>
>    https://github.com/D-Programming-Language/dmd/pull/443
>
> ----
> This patch is an additional enhancement of opDollar (issue 3474 and #442).
> It would enable the mixing operator overloadings of indexing and slicing.
>
> The expression:
>    a[$-1, 2..$]
> Translated to:
>    a.opIndex(a.opDollar!0 - 1, a.opSlice!1(2, a.opDollar!1))
>
> If it is possible, the interval lwr..upr inside bracket is converted
> to a.opSlice!(dimension)(lwr, upr).
> This enhancement doesn't break existing codes.
>
> (Same table more readable is in
>   https://github.com/D-Programming-Language/dmd/pull/443 )
>
>     | expression         | newly added overloading  -->
> exists/fallbcked overloading
> ---+--------------------+------------------------------------------------------------
>     | a[i0, ...]         | xxx  -->  a.opIndex(i0, ...)
>     | a[]                | a.opIndex()  -->  a.opSlice()
>     | a[l..u]            | a.opIndex(a.opSlice!0(l, u))  -->  a.opSlice(l, u)
>   v | a[l..u, ...]       | a.opIndex(a.opSlice!0(l, u), ...)  -->  xxx
> ---+--------------------+------------------------------------------------------------
>     | op a[i0, ...]      | xxx  -->  a.opIndexUnary!op(i0, ...)
>     | op a[]             | a.opIndexUnary!op()  -->  a.opSliceUnary!op()
>     | op a[l..u]         | a.opIndexUnary!op(a.opSlice!0(l, u))  -->
> a.opSliceUnary!op(l, u)
>   v | op a[l..u, ...]    | a.opIndexUnary!op(a.opSlice!0(l, u), ...)  -->  xxx
> ---+--------------------+------------------------------------------------------------
>     | a[i0, ...] = v     | xxx  -->  a.opIndexAssign(v, i0, ...)
>     | a[] = v            | a.opIndexAssign(v)  -->  a.opSliceAssign(v)
>     | a[l..u] = v        | a.opIndexAssign(v, a.opSlice!0(l, u))  -->
> a.opSliceAssign(v, l, u)
>   v | a[l..u, ...] = v   | a.opIndexAssign(v, a.opSlice!0(l, u), ...)  -->  xxx
> ---+--------------------+------------------------------------------------------------
>     | a[i0, ...] op= v   | xxx  -->  a.opIndexOpAssign!op(v, i0, ...)
>     | a[] op= v          | a.opIndexOpAssign!op(v)  -->  a.opSliceOpAssign!op(v)
>     | a[l..u] op= v      | a.opIndexOpAssign!op(v, a.opSlice!0(l, u))
> -->  a.opSliceOpAssign!op(v, l, u)
>   v | a[l..u, ...] op= v | a.opIndexOpAssign!op(v, a.opSlice!0(l, u),
> ...)  -->  xxx
>
> Thanks.
>
> Kenji Hara
>




More information about the Digitalmars-d mailing list