On Wednesday, 3 June 2020 at 10:24:44 UTC, Simen Kjærås wrote:
On Wednesday, 3 June 2020 at 09:39:34 UTC, Basile B. wrote:
You can use this template:
enum Exists(alias T) = is(typeof(T));
I don't know if there's a faster way bu this technic is used,
notatbly in phobos, to workaroud issues of double declaration
in `static foreach`
enum Exists(alias T) = is(typeof(T));
static assert(!Exists!bar); // undefined identifier bar
--
Simen
This is because the template parameter must be resolved to a
valid symbol or type.
This version other version bypass the problem:
---
enum Exists(string s) = is(typeof(mixin(s)));
void main()
{
static if (!Exists!"foo")
int foo;
foo = 42;
}
---