[Proposal] Additional operator overloadings for multidimentional indexing and slicing
Gor Gyolchanyan
gor.f.gyolchanyan at gmail.com
Thu May 31 23:50:01 PDT 2012
This is awesome!
I would think, that making ranges like x..y a first-class object would
solve all problems. In that case opSlice would return the slice, rather,
then use it internally.
On Fri, Jun 1, 2012 at 5:57 AM, kenji hara <k.hara.pg at gmail.com> 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
>
--
Bye,
Gor Gyolchanyan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120601/04023eed/attachment-0001.html>
More information about the Digitalmars-d
mailing list