Version block "conditions" with logical operators

Tomer Filiba via Digitalmars-d digitalmars-d at puremagic.com
Tue May 10 04:12:58 PDT 2016


Hey guys,

Looking at our code base (weka), I realized it would be really 
useful if we had logical operators (negation, conjunction, 
disjunction) in the version's "condition" clause. Here's what I 
have in mind:

version(!extra_checks) {
     ...
}

version(dlang_ver_2069 || dlang_ver_2070) {
     ...
}

Today we have lots of ugly code like

version(unittest) {} else { ... }

and bad-old copy-paste for the logical-or case I mentioned.

Is there any reason for that versions can't take compound logical 
conditions? Alternatively, an isVersion(x) predicate that I could 
use in a static if could do the trick -- although I think 
``version(x || y)`` is more readable than ``static if 
(isVersion(x) || isVersion(y))``

I think it could be a useful feature. Any thoughts?

-tomer


More information about the Digitalmars-d mailing list