Neater "not version (...)" ?
Simen Kjærås
Simen.kjaras at gmail.com
Wed Sep 16 19:27:10 UTC 2020
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
More information about the Digitalmars-d-learn
mailing list