【发布时间】:2017-08-06 12:02:39
【问题描述】:
有什么方法可以为嵌套模板类加上 using 关键字的别名?像这样的
template <typename... Types>
struct Something {
template <typename... TypesTwo>
struct Another {};
};
template <typename... Types>
template <typename... TypesTwo>
using Something_t = typename Something<Types...>::template Another<TypesTwo...>;
int main() {
Something_t<int><double>{};
return 0;
}
此答案template template alias to a nested template? 显示了一种方法,但如果两个参数包都是可变参数,则该方法将不再有效,因为编译器将不知道从哪里开始以及在哪里结束类型列表。
【问题讨论】:
-
为什么需要这种特定的方式?您可以稍微更改代码并使用类似的代码
Something_t<int>::Something2<double> -
@LmTinyToon 没有它是可能的,但我只是想知道它是否是一件事。
-
@LmTinyToon 因为他很好奇...:P
-
我不知道别名,但您可以通过使用分隔符类型使用老式 struct-with-typedef 构建类似的东西。
-
@cdhowie 你的意思是类型列表之间的分隔符来分隔它们?
标签: c++ c++11 templates c++14 variadic-templates