通常的模板结构可以是专用的,例如,
template<typename T> struct X{}; template<> struct X<int>{};
C 11为我们提供了表达模板typedef的新酷用语法:
template<typename T> using YetAnotherVector = std::vector<T>
有没有办法使用类似于结构模板的特化的构造为这些定义模板特化?我尝试了以下方法:
template<> using YetAnotherVector<int> = AFancyIntVector;
但它产生了编译错误.这有可能吗?
解决方法
没有.
但您可以将别名定义为:
template<typename T> using YetAnotherVector = typename std::conditional< std::is_same<T,int>::value,AFancyIntVector,std::vector<T> >::type;
希望有所帮助.
原文地址:https://www.jb51.cc/c/110533.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。