【发布时间】:2019-06-05 08:39:48
【问题描述】:
假设我有一个类型
template<typename ...Ts>
struct typelist {};
我需要从此列表中获取子列表:
template<int startInclusive, int stopExclusive, typename ...Ts>
struct sublist {
using type = ?; //
};
例如
sublist<1, 3, int, float, double, char>::type == typelist<float, double>
当start = 0 我有一个有效的尾部实现时:
template<typename ...Ts>
struct typelist {};
template<int N, typename T, typename ...Ts>
struct tail {
using type = typename tail<N - 1, Ts...>::type;
};
template<typename T, typename ...Ts>
struct tail<0, T, Ts...> {
using type = typelist<T, Ts...>;
};
using T = tail<1, int, double>::type;
#include <typeinfo>
#include <cstdio>
int main() {
::printf("%s\n", typeid(T).name());
}
但是,我无法为 start > 0 找到任何工作
【问题讨论】:
标签: c++ variadic-templates typelist