使用的类型别名如何指定依赖于模板参数的模板模板参数
How can a type alias with using specify a template template argument dependent on a template argument?
最小示例:
template<template<class ...> class>
struct templ {};
template<class T>
using special = templ<T::type>;
int main() {}
clang++:
test.cpp:5:23: error: template argument for template template parameter must be a class template or type alias template
using special = templ<T::type>;
事实上,我的意思是说T::type
是一个类模板,例如
struct detail1 {
template <class T>
using type = std::vector<T>;
};
struct detail2 {
template <class T>
struct type {};
};
但怎么能这么说呢?g++建议使用typename T::type
,但这对我来说是错误的,事实上,这并不能解决错误。
您需要指定type
是一个模板:
template<class T>
using special = templ< T::template type>;
这是必需的,因为T::type
依赖于模板参数T
。
另请参阅"template"answers"typename"关键字的位置和原因?
相关文章:
- 类成员函数参数列表是否可以依赖于模板参数?
- 如何定义依赖于参数包转换的函数的返回类型
- C++ 使函数调用依赖于模板参数
- 如何初始化依赖于先前条目的可变参数模板?
- 如何修复"没有依赖于模板参数的参数'glGenVertexArrays'......"C++ 中的错误
- 运算符<<依赖于参数的查找不在全局命名空间中查找
- 依赖于其他模板参数的模板参数
- 使用不依赖于方法模板参数的enable_if
- 如何定义具有依赖于符号调试的参数的函数
- 如何让成员函数实现依赖于类的模板参数?
- 如何避免参数数量依赖于条件的调用分支?
- 为什么在这种情况下不考虑依赖于参数的查找?
- 如何定义依赖于模板参数的类型定义
- 类型依赖于可变参数模板的类
- C++是否可以创建依赖于单个构造函数参数的派生类而不是bass类
- 我如何避免使用依赖于参数的查找明确专门化模板化功能
- 为什么默认参数不能依赖于非默认参数?
- 为什么在语句"std::cout << std::endl;"中使用时需要命名空间限定,给定依赖于参数的查找?
- C++ 错误:"没有依赖于模板参数的'setw'参数
- 依赖于模板参数的范围查找