This is related to my earlier post. I\'d like to know why one attempted solution didn\'t work.
template /* A */
size_t num_
Apropos the usefulness/uselessness of free variadic function templates: the usual use case for these is to have a variadic function parameter list, in which case a regular overload for the empty case will do just fine:
size_t num_args()
{
return 0;
}
template /* B */
size_t num_args (H h, T... t)
{
return 1 + num_args(t...);
}
As far as I can see, the following abuse of enable_if ought to work as a solution to your original question:
#include
// Only select this overload in the empty case
template
typename std::enable_if<(sizeof...(T) == 0), size_t>::type
num_args()
{
return 0;
}
template
size_t
num_args()
{
return 1 + num_args();
}
(Edit2: Reversed the order of the overloads to make the code actually compile)