部分类专门化只是编写完全专门化的另一种方式吗?
Is partial class specialization just a different way of writing a full specialization?
这两种专门化在本质上是做同样的事情吗?
//generic:
template<class T>
struct A{
...
}
template<class T>
struct A<int>{
...
}
template<>
struct A<int>{
...
}
也就是说,在我看来,任何部分专门化都可以重写为完全专门化。
不,不是。在图灵的焦油坑里,每一种足够强大的编程技术都是等价的。
template<typename A, typename B>
struct foo:std::false_type {};
template<typename T>
struct foo<T,T>:std::true_type {};
这里的,我的部分特化将两个参数映射为一个。更高级的东西,比如:
template<typename T>
struct foo<T,std::vector<T>>:std::integral_constant<int, 7> {};
也可以。
您甚至可以使用单个参数template
:
template<typename T>
struct is_func_signature : std::false_type {};
template<typename R, typename... Args>
struct is_func_signature< R(Args...) >: std::true_type {};
,其中我们对许多类型参数进行模式匹配,并提取它们。
部分专门化是对第一个接口有效的参数进行模式匹配的游戏。
相关文章:
- 文本冒险游戏 - 如何区分一种项目类型与另一种项目类型以及如何构建项目类/子类
- 为什么一种算法在相同的时间复杂度下比另一种算法更快?
- 当 c++ 需要一种数据类型并获取另一种数据类型时会发生什么?
- 另一种类型的智能ptr,比如具有弱refs的unique_ptr
- 只需要知道我在c ++中打印模式的方式是否有效,或者有另一种方法可以有效地做到这一点
- void* 数组将元素转换为另一种类型
- 在C++中使用另一种语言
- 将 X 坐标从一种分辨率转换为另一种分辨率
- 在 c++ 中将一种结构类型分配给另一种类型
- 如何在一种方法中创建对象并在另一种方法中使用它
- 常量静态成员函数:有另一种方法可用吗?
- 将空基类优化对象强制转换为另一种类型是否会破坏严格的别名?
- 如何将程序从主发送到另一种方法
- 如何使用shared_ptr或推荐另一种方法(unique_ptr)
- 存储多种颜色并从一种颜色切换到另一种颜色
- 如何测试指针类型是否可以安全地转换为另一种指针类型?
- 尝试用另一种语言解密时 AES 解密错误
- 在C++编程中继续下一行的另一种方法是什么?
- 将 32 位浮点数和不强制转换的 32 位整数与双精度进行比较,当其中一个值可能太大而无法完全适合另一种类型时
- 部分类专门化只是编写完全专门化的另一种方式吗?