Re: Why is this ambiguous? (Variadic template overloading.)
Am 15.12.2012 01:33, schrieb Scott Prager:
In section 14.5.6.2 of the standard, it shows an example like this:
template<class T, class... U> void f(T, U...);
template<class T > void f(T);
void g( int i ) {
f(&i); // ambiguous
}
Why is the overload without the empty parameter pack not preferred?
The reasoning was based on the comparison with ellipses or function
default arguments such as in the following example:
template<class T> void f(T);
template<class T> void f(T, int=1);
template<class T> void g(T);
template<class T> void g(T, ...);
int main() {
int i = 42;
f(i); // Error: ambiguous
g(i); // Error: ambiguous
}
Arguably there exists now a consistency argument here when referring to
empty parameter packs. Question is whether Parameter packs resemble
sufficiently with the former two function forms in this regard.
This has bugged me for as long as I've known of it.
You are not the first one. The current state has lead to new CWG issues, see
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1395
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1432
There is some tendency that the current ambiguity rule in regard to
parameter packs could be changed to support your use-case.
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]