use*_*020 7 c++ variadic-templates c++11
例如
template<typename... Ts>
LastTypeOfTs f();
Run Code Online (Sandbox Code Playgroud)
如何返回最后一种可变参数模板?
你可以做一个模板递归,如下所示:
template<typename T, typename... Ts>
struct LastTypeOfTs {
typedef typename LastTypeOfTs<Ts...>::type type;
};
template<typename T>
struct LastTypeOfTs<T> {
typedef T type;
};
template<typename... Ts>
typename LastTypeOfTs<Ts...>::type f() {
//...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
366 次 |
| 最近记录: |