make (a < b < c) illegal?

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Wed Feb 7 19:51:06 PST 2007


Derek Parnell wrote:
> class Foo { . . . }
> class Bar { . . . }
> 
> Foo f = new Foo;
> Foo g = new Foo;
> Bar b = new Bar;
> 
> if (ordered( f,b,g ) ) ...
> 
> BANG! The template doesn't know about Foo and Bar, so there is no match. In
> fact, just getting a template for built-in types requires a few thousand
> combinations of a,b,c signatures and aliases to make it palatable.
> 
> That is why I thought mixin-expressions might be more useful in this case -
> working at the textual level rather than the template-matching level. But I
> do know how to do it.

It's really simple:

bool ordered(T, U, V)(T a, U b, V c)
{
   return a < b && b < c;
}

Expanding this to multiple arguments is also quite simple, but left as 
an exercise. :o)


Andrei



More information about the Digitalmars-d mailing list