OpSlice for Ndim arrays?

Oskar Linde olREM at OVEnada.kth.se
Sat Mar 11 03:45:36 PST 2006


Ivan Senji wrote:

> Oskar Linde wrote:
> 
> ...
> 
>> 
>> void main() {
>>   int a = 1;
>>   float b = 5.6;
>>   long c = 3;
>>   char[] d = "test";
>>   func(a,b,c,d);
>> }
>> 
>> ---
>> 
>> And guess what? This prints:
>> 
>> Got argument: (int) 1
>> Got argument: (float) 5.6
>> Got argument: (long) 3
>> Got argument: (char[]) test
>> Done!
>> 
>> All types are deduced at compile time!
>> 
>> Notice the neat implementation of realFunc(). All other templates could
>> be put in a library. I bet the func()-wrapper could declared by a mixin!
>> 
>> So all we need to support multidimensional splice/indexing is to make ..
>> evaluate into:
>> 
>> struct Sequence {
>>         size_t start,end;
>> }
>> 
>> and we are set.
>> 
> 
> 
> I kind of like the idea, but not sure if it is maybe to late for
> something like that, and not sure if it will cause any problems.

There is fortunately an obvious fallback:

If the class has no opIndex(Sequence) overload, a depreciable
opSplice(s.start,s.end) gets called.

/Oskar



More information about the Digitalmars-d mailing list