Neater "not version (...)" ?

Vladimirs Nordholm v at vladde.net
Wed Sep 16 19:04:24 UTC 2020


On Wednesday, 16 September 2020 at 18:54:45 UTC, Jacob Carlborg 
wrote:
> On 2020-09-16 19:53, Vladimirs Nordholm wrote:
>> Hello.
>> 
>> I wonder if there is a better way to compile something if the 
>> current operating system is _not_ a specific platform.
>> 
>> For example, I only want some code to compile if the operating 
>> system is not Windows. Currently I do this:
>> 
>>      version (Windows)
>>      {
>>      }
>>      else
>>      {
>>          // ... my code
>>      }
>> 
>> Is there a neater version of this, like `!version (Windows) { 
>> /+ ... my code +/ }` ?
>
> The workaround for that is to define booleans for all versions 
> and then use `static if`:
>
> 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!


More information about the Digitalmars-d-learn mailing list