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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Sep 1 16:29:57 UTC 2020


On 9/1/20 10:00 AM, Steven Schveighoffer wrote:
> On 9/1/20 9:32 AM, Ogi wrote:
>> 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
>>>
>>> -- 
>>> /Jacob Carlborg
>>
>> I am aware of that. I mean that the enum workaround for version 
>> condition is the indication of its poor design.
>>
>> The syntax is unreasonably restrictive. I can see the point of 
>> prohibiting complex expressions (like `version (Windows || (POSIX && 
>> !LDC))`), but something as simple as version(!Windows) would be harmless.
> 
> In fact, I think version(a || b) would be the only thing we need to add, 
> as the code you need to write to reproduce such a thing is horrendous, 
> and the alternative is duplicating code.
> 
> You can already do version(a) version(b) to get the effect of &&.
> 
> `Not` is problematic, because you should really write code based on what 
> the version is, not for everything else (for the most part), and the 
> "not" can also be done via the slightly ugly but still reasonable 
> version(x) {} else ...
> 
> But Walter is never going to approve any changes here, as this is one 
> area where he will not budge, due to past experience with the C 
> Preprocessor abuse. So this discussion is only academic. Just use the 
> workarounds and move on.

So for the or we have something like:

version(a) version = a_or_b;
else version(b) version = a_or_b;

Not too bad if you don't have many. And if you do:

https://run.dlang.io/is/CZ5B6z

I'll see myself out.


More information about the Digitalmars-d mailing list