Eponymous template with static if
Steven Schveighoffer
schveiguy at gmail.com
Thu Aug 10 17:06:47 UTC 2023
On 8/10/23 12:44 PM, Michael Galuza wrote:
> 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
> }
> ```
Oh nice! I wish I had known this was in there I would have just pointed
at it.
>
> I bet that this paragraph was added immediately after my question.
The site is on github ;)
https://github.com/dlang/dlang.org/commit/190da42b6d6fe0abc205fda66a1d0e4086c5cf5c
-Steve
More information about the Digitalmars-d
mailing list