opDollar

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Sep 8 20:55:11 PDT 2008


Bill Baxter wrote:
> On Tue, Sep 9, 2008 at 9:37 AM, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>> Denis Koroskin wrote:
>>> 4) We need some way of supporting dollar notation in user containers. The
>>> hack of using __dollar is bad (although it works).
>> It doesn't work for multiple dimensions. There should be an opDollar(uint
>> dim) that gives the library information on which argument count it occured
>> in. Consider:
>>
>> auto x = matrix[$-1, $-1];
>>
>> Here the dollar's occurrences have different meanings. A good start would be
>> to expand the above into:
>>
>> auto x = matrix[matrix.opDollar(0)-1, matrix.opDollar(1)-1];
>>
> 
> Actually __dollar can be made to work with a bit of overhead.  Make
> __dollar be a particular struct type, say EndRelativeIndex, that holds
> an integer offset and has overloaded opAdd and opSub, then make
> overloads for Matrix opIndex that accept that struct type.  A
> "sufficiently smart compiler" could probably even get rid of the
> overhead.
> 
> But all that trickery would be unnecessary if opDollar existed and
> behaved as you suggest.

That's a nice trick! But shhh, let's convince Walter do the right thing 
while he's bent on making ranges work.

Andrei



More information about the Digitalmars-d-announce mailing list