Eponymous template with static if

Paul Backus snarwin at gmail.com
Mon Aug 14 14:49:06 UTC 2023


On Monday, 14 August 2023 at 03:18:17 UTC, Tejas wrote:
>
> D has [template 
> constraints](https://dlang.org/spec/template.html#template_constraints) that will do that for you(but I don't think it works when you explicitly use `template` keyword):

You can use constraints with the `template` keyword. They attach 
to the template itself, not the function:

```d
template square(T)
if (is(T)) // <-- right here
{
     T square(T param) { return param*param; }
}
```


More information about the Digitalmars-d mailing list