Eponymous template with static if

Michael Galuza riddlermichael at gmail.com
Thu Aug 10 16:44:44 UTC 2023


On Wednesday, 9 August 2023 at 16:55:04 UTC, Michael Galuza wrote:
> Why? What I missed?

Oh, I'm so stupid :-( `static if` restriction described in 
[26.1.1.1.2](https://dlang.org/spec/template.html#ifti-restrictions):
> When the template parameters must be deduced, the eponymous 
> members can't rely on a `static if` condition since the 
> deduction relies on how the members are used:
```d
template foo(T)
{
     static if (is(T)) // T is not yet known...
         void foo(T t) {} // T is deduced from the member usage
}

void main()
{
     //foo(0); // Error: cannot deduce function from argument types
     foo!int(0); // Ok since no deduction necessary
}
```

I bet that this paragraph was added immediately after my question.


More information about the Digitalmars-d mailing list