How to use $ in UDTs...
Don Clugston
dac at nospam.com.au
Thu Nov 22 05:25:21 PST 2007
Don Clugston wrote:
> Oskar Linde wrote:
>> Bill Baxter wrote:
>>
>>> Anyway, f[i][j][k] syntax is much more difficult to read than
>>> f[i,j,k]. So I think the latter is what we should be shooting for.
>>
>> I agree, and for what it is worth it is possible to implement
>> multidimensional indexing and slicing for UDTs today. The only thing
>> lacking is the ability to use the .. and $ tokens. For example:
>>
>> f[i, all, all, j, all, end-1, all, range(1, end)]
>>
>> gets translated into quite optimal code. The only variables that get
>> passed to the indexing function is (i,j,1,1) and no temporaries need
>> to be created. I guess that with some additional compiler supported
>> sugaring, the above could become something like:
>>
>> f[i, .. , .. , j, .. , $-1, .. , 1..$]
>
> Try putting this line at the top of your file.
>
> enum : int { __dollar = int.max }
>
> Of course you have to add (length-int.max) to any indices you get, for
> any index > (int.max-length).
>
> Gotta love these easter eggs....
BTW this means you can use arrays as an approximation to a slice, and write:
f[i, [0,$], [0,$], k, [0,$], $-1, [0,$], [1,$] ].
And every index element will be int or int[2], depending on whether it's a slice
or an index.
Of course you can define
const all= [0,int.max];
if you prefer that.
More information about the Digitalmars-d
mailing list