Version block "conditions" with logical operators

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


On Tuesday, 10 May 2016 at 11:12:58 UTC, Tomer Filiba wrote:
> Alternatively, an isVersion(x) predicate that I could use in a 
> static if could do the trick

Well, I've come up with

template isVersion(string ver) {
     mixin(format(q{
         version(%s) {
             enum isVersion = true;
         }
         else {
             enum isVersion = false;
         }
     }, ver));
}

pragma(msg, isVersion!"foo");     // false
pragma(msg, isVersion!"assert");  // true

But it feels hackish too

-tomer


More information about the Digitalmars-d mailing list