Conditional compilation on availability?

Tom S h3r3tic at remove.mat.uni.torun.pl
Sun Jul 9 07:37:03 PDT 2006


Fredrik Olsson wrote:
> But for a more general case perhaps:
> static if(expression) should yield false if expression is false, _or_ if 
> the expression can not be resolved. So that for example these could work:
> static if (toString(int)) { /* jupp std.strings probably imported */ }
> static if (T.nan) { /* Would seem we have a float */ }
> etc.
> 
> But that is just wishes.

I'd be against it. At first it looks like a cool idea, until you think 
about modifying existing code. Say, you statically check some condition 
in your code, e.g. 'static if (foo.bar > 10)'. Then after a few 
committee meetings, it's decided that 'bar' should be renamed to 'baz'. 
So you get to work to change all 'bar' occurrences to 'baz'. But if you 
miss one... then 'static if (foo.bar > 10)' would always be false. An 
error should be triggered in that case IMO.

You can still do these tests by using the 'static if (is(typeof()))' combo.


-- 
Tomasz Stachowiak  /+ a.k.a. h3r3tic +/



More information about the Digitalmars-d-learn mailing list