Question about tuple as template parameter
Bill Baxter
dnewsgroup at billbaxter.com
Tue Apr 22 04:05:21 PDT 2008
Max Samukha wrote:
> Why the compiler chooses the template with tuple paramer? Isn't the
> template with type parameter more 'specialized'?
>
> template Foo(T)
> {
> pragma(msg, "Type");
> }
>
> template Foo(TT...)
> {
> pragma(msg, "Tuple");
> }
>
> alias Foo!(int) foo;
> ----
> Outputs: Tuple
I don't think the spec makes any promises about that sort of thing.
Generally speaking you're on shaky ground any time you try to overload
templates in D.
Can you not put a "static if(TT.length==1)" in the tuple version?
Also you could try making the tuple one be
template Foo(T0,T1,TN...) {
alias Tuple!(T0,T1,TN) TT;
}
So that it takes a min of 2 args to differentiate. And then add a zero
arg version if you need that too.
But I think Walter's idea with templates is that to make it simpler any
ambiguity should just be an error. So that you don't end up with a
bunch of crazy rules that no two compilers implement quite the same.
--bb
More information about the Digitalmars-d-learn
mailing list