static assert(version(x)) ?

Robert M. Münch robert.muench at saphirion.com
Thu Nov 28 10:22:55 UTC 2019


On 2019-11-27 18:50:07 +0000, Johan Engelen said:

> On Tuesday, 26 November 2019 at 12:53:02 UTC, Jonathan M Davis wrote:
>> On Tuesday, November 26, 2019 4:29:18 AM MST S.G via Digitalmars-d-learn wrote:
>>> On Tuesday, 26 November 2019 at 10:24:00 UTC, Robert M. Münch
>>> 
>>> wrote:
>>>> How can I write something like this to check if any of a set of 
>>>> specific versions is used?
>>>> 
>>>> static assert(!(version(a) | version(b) | version(c)):
>>>> 
>>>> The problem is that I can use version(a) like a test, and the
>>>> symbol a is not accessbile from assert (different,
>>>> non-accessible namespace).
>>> 
>>> BTW D language designers are against boolean eval of version. It's not 
>>> a technical restriction, it's just that they don't want this to work.
>> 
>> ...
>> static if can be used instead of version blocks to get boolean 
>> conditions, and local version identifiers can be defined which combine 
>> some set of version identifiers, but such practices are discouraged for 
>> D programmers in general, and they're basically forbidden in official 
>> source code. The only case I'm aware of where anything like that is 
>> used in druntime or Phobos is for darwin stuff, since darwin isn't a 
>> predefined identifier.
> 
> `xversion` is a simple and effective and useful tool, used in dmd source:

That's pretty neat... going to try this.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



More information about the Digitalmars-d-learn mailing list