template class myclass
{
public:
template void mymethod(Args... args)
{
// Do interesting stuff
}
};
For the number of arguments constraint you can easily check if sizeof...(Args) == N
but for checking if all the arguments are doubles you need to build a recursive type trait that checks std::is_same
for each of the arguments.
template
struct are_same : std::true_type
{};
template
struct are_same : std::true_type
{};
template
struct are_same :
std::integral_constant::value && are_same::value)>
{};
Notice are_same
is first declared and then specialized.
Then just implement the constraint in your method return type using std::enable_if
by taking advantage of SFINAE.
template class myclass
{
public:
template
typename std::enable_if<(are_same::value && sizeof...(Args) == N), void>::type
/* void */ mymethod(Args... args)
{
// Do interesting stuff
}
};