这是部分模板专用化吗?
Is this partial template specialization?
本文关键字:专用 更新时间:2023-10-16
我试图通过一些例子来理解模板元编程中的类型函数。
我创建了一个从类型中删除引用的示例。
template <class T>
struct remove_reference
{ using type = T; };
template <class T>
struct remove_reference<T&>
{ using type = T; };
int main(){
typename remove_reference<int&>::type a;
}
我的问题是,这是否是使用部分模板专用化实现的,如果我们称之为其他东西?
我觉得这是部分的,因为我们没有为特定类型定义它,但我也觉得这不是因为我们有同样多的模板参数。 命名对于理解类型函数可能并不重要,但是如果我解释它,我不想教别人错误的名字。
是的,这是部分专业化,因为您仅限于与模式T&
匹配的东西。
您不需要拥有更少的模板参数,甚至可以拥有更多。
例如template <typename Callable>
struct function_something { ... }; // Any functor type
template <typename Ret, typename Args...>
struct function_something<Ret(Args...)> { ... }; // Specialises free functions
template <typename Class, typename Ret, typename Args...>
struct function_something<Ret(Class::*)(Args...)> { ... }; // Specialises member functions
相关文章:
- .cpp和.h文件中的模板专用化声明
- 调用专用模板时出错"no matching function for call to [...]"
- 模板专用化(按容器):value_type
- 静态数据成员模板专用化的实例化点在哪里
- 特征 3 类的模板专用化
- Visual Studio 2017 不允许我创建 C++ 专用模板
- 字符串化递归的"std::vector<std::vector<...>>"而不使用部分模板函数专用化
- 具有常量引用参数的函数模板专用化
- 使用其他模板的模板专用化
- 使用专用显卡进行 OpenGL 渲染时帧速率较低
- 嵌套模板显式专用化
- 如何检查模板专用化是否是基本模板的子类?
- C++:部分模板专用化用例
- 通过依赖类型使用非类型模板参数的单类型模板参数类模板的部分专用化
- 使用对象的基类部分模板专用化对对象进行哈希处理::哈希
- 在 C++20 中是否不再允许在 std 中对程序定义类型的函数模板进行专用化?
- 为什么依赖模板类型在部分专用化中不可推导?
- 如何为静态常量模板化专用整数值分配存储
- 模板类的部分模板专用化,如 std::function
- 合并一组模板专用化