template specialization question
daoryn
poreas at asiot.po
Mon Feb 1 14:19:38 PST 2010
Ellery Newcomer Wrote:
> I haven't gotten around to templates yet, so I don't grok them quite as
> well as I'd like, but it looks like DMD is having trouble deducing T
> from the parameter given.
>
> print([1,2,3]) fails to match the specialized template, even when the
> general template is removed.
>
> If you force the template parameter, it does what you would expect:
>
>
> print!(int)(3);
> print!(int[3])([1,2,3]);
>
>
> Calling print(T)
> int
> Calling print(T[])
> int
>
> Can't say whether this belongs in bugzilla or not. It might.
>
> On 01/31/2010 12:49 PM, daoryn wrote:
>
> >
> > I expected it to output "calling print(T[])" on the second "print". Would this be a bug or did I misunderstand the template specialization?
> >
>
The whole point of specialisation (and of templates in general) is to have functions that work for any type. Having to forcibly specify a type is like casting to a specific overload of a function. Why add clutter to the syntax when the language advertises automatic type inference?
More information about the Digitalmars-d-learn
mailing list