【发布时间】:2014-03-20 08:11:18
【问题描述】:
如果我有一个模板函数,它接受已知数量的模板参数,我可以使用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
}
您将如何编写这个条件定义?
【问题讨论】:
标签: c++ templates c++11 variadic-templates enable-if