Hello all, Following (bit weird ;-) code shows weird case of variadic template function specialization, however I am not sure it is legal, (atleast I haven't found any wording that would prevent such use):
enum SelectFoo {S1, S2, S3}; struct A { template <SelectFoo Selector_, typename... Args_ > void foo (Args_...); }; template <> void A::foo<S1> (int) {} // #1 compiles fine template <> void A::foo<S2> () {} // #2 this won't compile (error: template-id 'foo<(SelectFoo)1u>' for 'void A::foo()' does not match any template declaration) template <> void A::foo<S3> (int, int) {} // #3 this won't compile too (error: template-id 'foo<(SelectFoo)2u>' for 'void A::foo(int, int)' does not match any template declaration) I have checked this code with g++-4.3.2 and g++-4.4.0-alpha20081010 (gentoo ebuild) It seems that variadic type pack Args_... is always treated as one parameter. When I have tried declaration like: template <SelectFoo, typename T_, typename... More_> void foo (T_, More_...); it could match specialization with two parameters only, 'foo(int, int)' in this example. If I would provide all three declarations ie. struct A { template <SelectFoo> void foo (); template <SelectFoo, typename T_> void foo (T_); template <SelectFoo, typename T1_, typename T2_> void foo (T1_, T2_); }; everything compiles fine, with both gcc and Comeau C/C++ online, as one would expect. My question is: whether all specializations (#1, #2, #3) should be accept, or it is just illegal use of variadic templates not reported here, and #1 is accepted incorrectly, or this is expected result? Piotr