An Impressive Feature Without Doc
Wei Li
oldrev at gmail.com
Wed Nov 14 09:20:51 PST 2007
downs Wrote:
> Wei Li wrote:
> > Just a moment ago, I met a cool feature but where is the specs for it?
> >
> > template Floats(T) {
> > static if(is(T : real)) {
> > alias T Floats;
> > }
> > }
> >
> > T min(T=Floats)(T x, T y) // Why we can write T=Floats instead of T=Floats!(T) ?
> > {
> > return x < y ? x : y;
> > }
> >
> > Regards
>
> This is one of D's template pitfalls; since min is never instantiated, it
> never actually checks if Floats is a valid thing to instantiate min with.
> (it's not; a template is not a type).
> You can see this by writing
>
> >
> > void main() {
> > auto fp=&min!();
> > }
> >
>
> which will make the compiler notice the error and barf.
> Thanks to KMD for pointing this out.
I got it, thanks for your explain.
Regards,
More information about the Digitalmars-d
mailing list