make (a < b < c) illegal?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Feb 8 04:03:23 PST 2007


Derek Parnell wrote:
> On Thu, 8 Feb 2007 10:50:56 +0000 (UTC), Michiel wrote:
> 
>>> I give up. I can't work out how to create this functionality
>>> for an arbitary number of arguments.
>> You need to use recursion, not loops. I'm not sure how the syntax works exactly,
>> but it might look something like this:
>>
>> bool ordered(T1, T2, Trest ...)(T1 first, T2 second, Trest rest) {
>>     return (first < second) && ordered(second, rest);
>> }
> 
> Maybe ... I tried many combinations based on that. Still no luck.
> 
> Show me something that compiles and runs, anyone?

Besides the foreach approaches already posted, this works as well:
-----
bool ordered(R...)(R args) {
     static if (args.length < 2)
         return true;
     else
         return (args[0] < args[1]) && ordered(args[1..$]);
}
-----

It seems DMD just doesn't like it if the first two parameters have 
separately templated types...



More information about the Digitalmars-d mailing list