make (a < b < c) illegal?
Reiner Pope
xxxx at xxx.xxx
Thu Feb 8 03:33:41 PST 2007
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);
> }
You can use a foreach-over-tuple instead of recursion:
bool ordered(T...)(T data)
{
foreach(i, d; data)
{
static if (i < data.length - 1)
if (! (d < data[i+1])) return false;
}
return true;
}
More information about the Digitalmars-d
mailing list