Templates with scope

drug drug2004 at bk.ru
Wed Jul 21 09:41:50 UTC 2021


But why do you think that `CanCompile` fails? It works for me:
```D
template CanCompile(alias symbol)
{
     enum CanCompile = __traits(compiles, { symbol = 10; });
}

mixin template CanCompile2(alias symbol)
{
     enum couldCompile = __traits(compiles, { symbol = 10; });
}

void main()
{
     int x = 20;

     static if (CanCompile!x)
     {
         x = 9;
     }

     assert(x == 9);

     mixin CanCompile2!x;
     static if (couldCompile)
     {
         x = 12;
     }

     assert(x == 12);
}
```


More information about the Digitalmars-d mailing list