如果我有一个模板函数,它接受已知数量的模板参数,我可以使用该enable_if
语句以及is_base_of
限制合法类型之类的东西。例如:
template <typename T>
typename enable_if<is_base_of<BaseClass, T>::value, void>::type
function() {
// do stuff with T, which is ensured to be a child class of BaseClass
}
现在假设我们想对可变参数模板做同样的事情——检查以确保所有类型都是特定基类的子类。
template <typename... T>
/* What goes here? */
function() {
// do stuff with the T types, which are ensured to be child classes of BaseClass
}
您将如何编写这个条件定义?