模板别名可以用于部分专用化吗
can template alias be used for partial specialization?
给定一个模板别名
template<unsigned U>
using uint_ = integral_constant<unsigned,U>;
的部分专业化
template<class T,class P>
struct size{};
作为
template <class T,unsigned U>
struct size<T,uint_<U>>{};
为clang 3.1生成一个警告template parameter can not be deduced
,而使用gcc 4.7 没有生成任何警告
那么,这是格式错误的代码吗?
代码在C++11中非常好。Clang的警告可以忽略。
另一个人说这是Clang bug。如果你像这个一样更改使用声明,你可以解决这个问题
template<unsigned T, unsigned U = T>
using uint_ = integral_constant<unsigned,U>;
作为一个有根据的猜测,显然Clang没有正确更新type-id中出现的模板参数的标识。因此,在您的示例中,它认为结果类型uint_<U>
引用了部分专业化的第一个参数(因为在uint_
中是这样,但在使用点上不是这样)。或者,您可以在使用时交换订单
template <unsigned U,class T>
struct size<T,uint_<U>>{};
相关文章:
- 使用类型特征的部分类专用化
- 将 CRTP 与部分类专用化结合使用?
- C++具有可变参数专用参数的模板,用于参数数量
- 部分模板专用化,用于展开特定大小的循环
- 类的可变参数模板部分专用化,用于限制模板参数的类型
- 针对多种类型的部分类模板专用化
- enable_if的模板专用化在 Clang 中失败,适用于 GCC
- 找不到用于专用化的定义的"内联"模板方法
- 用于函数签名的专用模板
- 参数包不在最后位置的部分类模板专用化
- 用于模板专用化的类似使用语句
- 具有多个参数的部分类模板专用化
- 模板别名可以用于部分专用化吗
- 部分模板专用化可能不适用于函数,但重载不是一回事吗?
- 函数指针类型和值的部分类专用化
- 是否有适用于 sigma.js兼容 json 文件的专用格式
- 如何使用类的属性作为模板参数/用于专用化
- unique_ptr<T> 用于数组专用化的 lambda 自定义删除器
- 模板专用化适用于 gcc,但不适用于 Visual Studio 10
- C++模板:专用成员函数,用于解决主模板中不明确的重载情况