More operators inside `is(...)` expressions

Steven Schveighoffer schveiguy at gmail.com
Sat Aug 29 00:39:44 UTC 2020


On 8/28/20 8:45 AM, Jacob Carlborg wrote:
> On Friday, 28 August 2020 at 07:22:51 UTC, Ogi wrote:
> 
>> There is one expression where allowing “!” would be much more 
>> beneficial — version condition. Currently we are forced to write 
>> something like:
>>     version (OSX) {} else {
>>         /* ... */
>>     }
>> when it could be just:
>>     version (!OSX) {
>>         /* ... */
>>     }
>> I am aware that it was Walter’s intention to make the version syntax 
>> simplistic, but I don’t think that allowing “!” would do any harm.
> 
> There's a workaround: define bool enums for all version identifiers and 
> use `static if` instead:
> 
> version (OSX)
>      enum OSX = true;
> else
>      enum OSX = false;
> 
> static if (!OSX) {}

I think someone posted this a while ago:

template staticVersion(string s)
{
   mixin("version(" ~ s ~ ") enum staticVersion = true; else enum 
staticVersion = false;");
}

-Steve


More information about the Digitalmars-d mailing list