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:
https://github.com/dlang/dmd/blob/53b533dc7fc5da604e7ebf457734766b4e96d900/src/dmd/globals.d#L21-L35

```
template xversion(string s)
{
enum xversion = mixin(`{ version (` ~ s ~ `) return true; else return false; }`)();
}

enum version_a = xversion!`a`;
```

-Johan

Reply via email to