Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check the DMD version in compile-time?

I can test that DMD is compiling the given code using version(DMD){}, but how can I check which version of it? (2.66/2.65 etc)

More concisely, I want to check that the @nogc modifier exists, and if not - define a dummy one.

I came up with a workaround:

static if(!__traits(compiles, ()@nogc{}))
{
    struct nogc;
}

but is there a better way? for example even checking directly for the existence of that specific modifier?

like image 736
ordahan Avatar asked Mar 19 '23 08:03

ordahan


1 Answers

You can use the predefined __VERSION__ constant.

See also the std.compiler module (version_major and version_minor, specifically) for an easier way to use it.

However, your workaround might be a better approach. It will allow the code to work correctly even for compiler builds between released versions.

like image 56
Vladimir Panteleev Avatar answered Mar 24 '23 04:03

Vladimir Panteleev