How can I check the DMD version at compile time?
I can check that DMD compiles the given code with version(DMD){}
, but how can I check which version? (2.66 / 2.65, etc.)
More succinctly, I want to check if a modifier exists @nogc
, 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 check directly for that particular modifier?
source to share
You can use a predefined constant __VERSION__
.
See also std.compiler ( version_major
and version_minor
in particular) for an easier way to use it.
However, a workaround might be a better one. This will allow the code to work correctly even to build the compiler between released versions.
source to share