Template type deduction and specialization
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 21 07:39:22 PDT 2015
On 5/21/15 10:15 AM, Daniel Kozák via Digitalmars-d-learn wrote:
> import std.stdio;
>
> void f(T:T*)(T* t)
> {
> writeln("before change this is not called");
> }
>
> void f(T)(T t)
> {
> writeln("before change this is called");
> }
>
>
> void main() {
> int val;
> f(&val);
> f!(int*)(&val);
> }
>
> now it prints:
> before change this is called
> before change this is not called
>
> but if we make change as you suggest this will be print:
>
> before change this is not called
> before change this is not called
>
Ugh, that was not what my reading of the docs seemed to suggest:
"Function template type parameters that are to be implicitly deduced may
not have specializations"
I misread that to mean *templates* that have specializations cannot be
used for IFTI. Now I see that the rule is talking not about templates
but *template type parameters*.
But the more I look at this, the more I think this is a bad code smell.
I can't see any logical reason to do something different with an
implicit deduction vs. an explicit call. Especially in the face of other
code that Can anyone come up a valid use case for this? Even one that is
a hack?
I'll note that if you replace the specialization with:
f(T : int *)(T t)
it calls the specialized version twice. Clearly, the rule is not
properly described or not properly implemented.
I would like to hear from Walter on this, what are the thoughts behind
this rule?
-Steve
More information about the Digitalmars-d-learn
mailing list