opSlice and $

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Wed Sep 12 08:43:35 PDT 2007


Daniel Keep wrote:

> Two ideas:
> 
> elemT[] opSlice(Repeat!(offset,2) xr, Repeat!(offset,2) yr);
> 
> c[1..$,2..$] --> c.opSlice(offset(1), offset.dollar(0),
>                            offset(2), offset.dollar(0));
> c[1..$,2..$-1] --> c.opSlice(offset(1), offset.dollar(0),
>                              offset(2), offset.dollar(-1));
> 
> You could create such a type by sacrificing the upper-most bit of a
> size_t type; if that bit is set, treat it as a one's complement signed
> offset from whatever "dollar" happens to be.
> 
> Other idea:
> 
> Tuple!(size_t, size_t) opDollar();
> 
> Or, if we aren't allowed to have tuple return types:
> 
> void opDollar(out size_t, out size_t);
> 
> That gives us multidimensional dollars.  Come to think of it, the second
> is probably the better syntax since it will allow for overloading based
> on how many dimensions the user is indexing on.  This could be useful
> for, say, matrices which could be accessed as columns of vectors, or
> individual scalars.
> 
> Just something to chew on :)

Or what about

retType opDollar(int dollar_idx = 0)(idxType);

It would also need some changes in the way compiler handles templated
methods and template default parameters currently. But I live in faith that
those will change :)

A bit OT, but I was browsing some older posts and came across several
instances of amazingly similar concepts that have been discussed lately
(for example ndim slices, macros and multiple return values). That just
makes me wonder whether time really is linear or are we stuck in an eternal
loop (modulo 42) ? :)



More information about the Digitalmars-d mailing list