More operators inside `is(...)` expressions
Simen Kjærås
simen.kjaras at gmail.com
Tue Sep 1 11:01:52 UTC 2020
On Tuesday, 1 September 2020 at 09:05:27 UTC, Jacob Carlborg
wrote:
> On Tuesday, 1 September 2020 at 07:11:45 UTC, Ogi wrote:
>
>> Why use `version` then?
>
> Because that's set automatically by the compiler. Here's a list
> of the predefined version identifiers set by the compiler [1].
>
> [1] https://dlang.org/spec/version.html#predefined-versions
Also, more versions can be set via the -version compiler flag:
https://dlang.org/dmd-windows.html#switch--version
Perhaps an even more useful version of the above trick:
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");
--
Simen
More information about the Digitalmars-d
mailing list