Template type deduction and specialization

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 19 23:31:11 PDT 2015


I don't understand why this behaves as it does. Given the 
following two templates:

```
void printVal(T)(T t) {
	writeln(t);
}
void printVal(T : T*)(T* t) {
	writeln(*t);
}
```

I find that I actually have to explicitly instantiate the 
template with a pointer type to get the specialization.

```
void main() {
	int x = 100;
	printVal(x);
	int* px = &x;
	printVal(px);        // prints the address
         printVal!(int*)(px)  // prints 100
}
```

Intuitively, I would expect the specialization to be deduced 
without explicit instantiation. Assuming this isn't a bug (I've 
been unable to turn up anything in Bugzilla), could someone in 
the know explain the rationale behind this?


More information about the Digitalmars-d-learn mailing list