On Saturday, 2 December 2023 at 15:48:02 UTC, Nick Treleaven wrote:
On Saturday, 2 December 2023 at 15:03:25 UTC, ryuukk_ wrote:
I wish we could use ``version`` as expression, to void the repetition:

```D
import std.stdio;

enum HasTest = version (Test) ? true : false;

Tomek SowiƄski wrote this template:
```d
enum bool isVersion(string ver) = !is(typeof({
          mixin("version(" ~ ver ~ ") static assert(0);");
    }));

static assert(isVersion!"assert");
static assert(!isVersion!"Broken");
```

I have something similar that i found somewhere here

```D

struct Version
{
    static bool opDispatch(string identifier)()
    {
        mixin("
            version(", identifier, ")
                return true;
            else
                return false;
        ");
    }
}


static if (Version.something == false)
{}
```

But i don't even use it since it requires me to import a module, it not worth it, i'd rather have version as expression

Reply via email to