static if with constant value

Bill Baxter dnewsgroup at billbaxter.com
Wed Dec 13 17:40:24 PST 2006


Sean Kelly wrote:
> 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

Yeh, that makes sense.  I think I'm going to need both kinds of tests 
eventually, actually.

--bb


More information about the Digitalmars-d-learn mailing list