Eponymous template with static if

sighoya sighoya at gmail.com
Tue Aug 15 10:25:56 UTC 2023


On Monday, 14 August 2023 at 14:49:06 UTC, Paul Backus wrote:
> 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; }
> }
> ```

Can you tell what `is(T)` is doing here?
 From the docs it seems to require `T` to be existing.
However, I don't know what this exactly means, as T anyway have 
to exist.


More information about the Digitalmars-d mailing list