问题
For example
template<typename... Ts>
LastTypeOfTs f();
How to return the last type of a variadic template?
回答1:
You could do a template recursion as below:
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() {
//...
}
LIVE DEMO
来源:https://stackoverflow.com/questions/26088683/how-to-return-the-last-type-of-a-variadic-template