Template type deduction and specialization
Daniel Kozak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed May 20 02:44:39 PDT 2015
On Wednesday, 20 May 2015 at 07:27:53 UTC, jklp wrote:
>
> ---
> import std.stdio;
>
> void printVal(T)(T t) {
> writeln(t);
> }
>
> void printVal(T: T)(T* t) {
> writeln(*t);
> }
>
> void main() {
> int x = 100;
> printVal(x);
> int* px = &x;
> printVal(px);
> }
> ---
>
> here it's selected correctly without explicit instantiation.
> But honestly i don't know why since the asterisk is removed
> from the T it looks quite incorrect.
No it is correct it is same as:
void printVal(T: int)(T* t) {
writeln(*t);
}
More information about the Digitalmars-d-learn
mailing list