C++ partial specialization of function templates 和 partial ordering of function template 的区别

本文详细介绍了C++中的函数模板偏特化(partialspecializationoffunctiontemplates)和偏排序(partialorderingoffunctiontemplate)概念。函数模板偏特化允许部分指定模板参数,而偏排序则是在多个偏特化版本中,根据模板参数范围选择最精确的版本进行调用。通过示例代码,阐述了这两种机制在实际编程中的应用和区别。

partial specialization of function templates 和 partial ordering of function template 的区别

概念辨析

区别

  • partial specialization of function templates 指函数模板偏特化,即显式地指定函数模板的部分模板参数而非全部参数;
  • partial ordering of function template 也是一种函数模板偏特化,但指的是模板参数范围上的偏特化。实际调用中,当有多个偏特化的函数模板匹配时,编译器会按照偏特化的精确程度(范围)进行排序,选择调用最精确的(范围最小的)版本

总结

函数模板偏特化(partial specialization of function templates)包括模板参数个数的偏特化和模板参数范围的偏特化,而 partial ordering of function template 指的就是模板参数范围的偏特化中,编译器所作的按照不同偏特化版本的匹配程度进行排序选择的动作

举例

partial ordering of function template

#include <iostream>

using namespace std;

template <class T>
void func(T) {
   
   
	cout << "func<T> is called!" << endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Air浩瀚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值