static if with constant value

Sean Kelly sean at f4.ca
Wed Dec 13 16:24:36 PST 2006


Bill Baxter wrote:
> Doh, I figured out why it does what it does now.  I had assumed that 
> floats and doubles didn't have .re and .im properties, so that that 
> would cause the is() check to fail.
> 
> So what's a better way to check for complexity of a type?
> I'd rather not have to list every complex type explicitly.  It's ugly 
> for one, but more importantly it precludes recognizing user types as 
> complex-like.
> 
> Maybe this is close enough?
> 
>    static if( is(T:cfloat) || is(T:cdouble) || is(T:creal) ) {...}

You can probably just do:

     static if( is(T:creal) ) { ... }

As far as I know, cfloat and cdouble are convertible to creal, so that 
should work.  I personally chose to list types in the traits templates I 
created, but that is because I want to be sure that they're exactly that 
type.  I generally don't want UDTs filtering through as well.

Sean


More information about the Digitalmars-d-learn mailing list