On Wednesday, 16 September 2020 at 19:04:24 UTC, Vladimirs Nordholm wrote:
On Wednesday, 16 September 2020 at 18:54:45 UTC, Jacob Carlborg wrote:
version (Windows)
    enum windows = true;
else
    enum windows = false;

static if (!windows)
{
    // ... my code
}

Ah, I guess it boils down to this then. Doesn't really make it "neater", but thank you for the tip!

I wrote this helper a little while back:

struct Version {
    template opDispatch(string name) {
mixin("version ("~name~") enum opDispatch = true; else enum opDispatch = false;");
    }
}

static if (Version.Windows) pragma(msg, "Windows machine");
static if (Version.linux) pragma(msg, "Linux machine");

Note that it only works for global versions, and those defined in the same module as Version.

--
  Simen

Reply via email to