简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM