c++ - [bug] partial ordering of templates
- Christof Meerwald (23/23) Mar 28 2005 DMC 8.42.5 compiles the following program without any errors, but the
-
Walter
(3/3)
Apr 20 2005
I don't think it should be ambiguous. Both D
and D<1,n> match, and ... -
Christof Meerwald
(7/10)
Apr 20 2005
But, D<1,n> isn't more specialized than D
. - Walter (5/14) Apr 20 2005 the
- Christof Meerwald (23/24) Apr 24 2005 I am afraid, there is still one more problem in 8.43.6n:
DMC 8.42.5 compiles the following program without any errors, but the template instantiation really should be ambiguous: template<int n, int m> struct D { static const int val = 0; }; template<int n> struct D<n, n> { static const int val = 1; }; template<int n> struct D<1, n> { static const int val = 2; }; int main() { return D<1, 1>::val; } bye, Christof -- http://cmeerw.org mailto:cmeerw at web.de xmpp:cmeerw at cmeerw.org ...and what have you contributed to the Net?
Mar 28 2005
I don't think it should be ambiguous. Both D<n,n> and D<1,n> match, and the partial specialization rules say that the one that is most specialized wins. D<1,n> is most specialized.
Apr 20 2005
Walter wrote:I don't think it should be ambiguous. Both D<n,n> and D<1,n> match, and the partial specialization rules say that the one that is most specialized wins. D<1,n> is most specialized.But, D<1,n> isn't more specialized than D<n,n>. If I remember correctly, you have to synthesize a unique constant for non-type template arguments and then try to deduce the template arguments of the other specialization. But in that case, argument deduction will fail, because the synthesized constant isn't equal to 1. bye, Christof
Apr 20 2005
"Christof Meerwald" <cmeerw web.de> wrote in message news:d45go5$31b3$1 digitaldaemon.com...Walter wrote:theI don't think it should be ambiguous. Both D<n,n> and D<1,n> match, andwins.partial specialization rules say that the one that is most specializedDarn it, I think you're right <g>.D<1,n> is most specialized.But, D<1,n> isn't more specialized than D<n,n>. If I remember correctly, you have to synthesize a unique constant for non-type template arguments and then try to deduce the template arguments of the other specialization. But in that case, argument deduction will fail, because the synthesized constant isn't equal to 1.
Apr 20 2005
Walter wrote:Darn it, I think you're right <g>.I am afraid, there is still one more problem in 8.43.6n: template<int n, int m> struct A { }; template<int n> struct A<n, n> { }; template<int n> struct A<1, n> { }; template<> struct A<1, 1> { }; int main() { A<1, 1> a; // Error: ambiguous match of class template partial specialization 'A' return 0; } Of course, in this case the specialization A<1, 1> should be used. BTW, this example compiles if I swap the order of A<n, n> and A<1, n>. bye, Christof
Apr 24 2005