make (a < b < c) illegal?

Daniel Giddings daniel.giddings at gmail.com
Thu Feb 8 03:56:30 PST 2007


To get recursion going you need add a 1 element case and a static if to 
handle the degeneration of the recursion to Michiel's version...

import std.stdio;

bool ordered( T )( T a )
{
 return true;
}

bool ordered( T1, T2, R... )( T1 a, T2 b, R remainder )
{
 static if( remainder.length > 0 )
  return a < b && ordered( b, remainder );
 else
  return a < b;
}

void main()
{
 writefln( ordered(1,2,4) );
 writefln( ordered(1,4,2) );
}



"Derek Parnell" <derek at psych.ward> wrote in message 
news:<mqx61f4cfl24.yz4pjbrcs05z.dlg at 40tude.net>...
> 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?
>
> -- 
> Derek Parnell
> Melbourne, Australia
> "Justice for David Hicks!"
> skype: derek.j.parnell 





More information about the Digitalmars-d mailing list