Change representation of dynamic arrays?

Janice Caron caron800 at googlemail.com
Sun Oct 21 00:59:37 PDT 2007


On 10/21/07, Oskar Linde <oskar.lindeREM at ovegmail.com> wrote:
> But that might be too much to ask for.

I think those are /excellent/ ideas.

So I assume opDollar would return some proxy type which represents
"offset from end", and looks something like

struct Dollar
{
    int offset = 0;
    static Dollar opCall(int n) { Dollar d; d.offset=n; return d; }
    Dollar opAdd(int n) { return Dollar(offset+n); }
    Dollar opAdd_r(int n) { return Dollar(offset+n); }
    Dollar opSub(int n) { return Dollar(offset-n); }
}

and x..y returns a Slice!(typeof(x),typeof(y)) where

struct Slice(T,U)
{
    T x;
    U y;
}

(no need to implement opDotDot - that can happen automatically), and
then opIndex knows to expect either an integer, a Dollar, or Slice
whose elements are integers or Dollars. (More exotic uses of course
can be imagined, but that would be enough to emulate current
behavior).

I like it!



More information about the Digitalmars-d mailing list