Templates with scope
Paul Backus
snarwin at gmail.com
Wed Jul 21 12:32:23 UTC 2021
On Wednesday, 21 July 2021 at 07:16:43 UTC, bauss wrote:
> Is there a way to make this logic work without using a mixin
> template.
>
> I'd prefer if using a plain template was possible, rather than
> using a mixin template, because it introduces some extra
> boilerplate.
```d
enum CanCompile(alias symbol) =
`__traits(compiles, { ` ~ symbol.stringof ~ ` = 10; })`;
void main()
{
int x = 20;
static if (mixin(CanCompile!x))
{
x = 10;
}
}
```
More information about the Digitalmars-d
mailing list