如何使用模板化类专门化模板化函数?
How do you specialise a templated function with a templated class?
所以我有一个模板化函数:
template<typename T>
int func(const T& input){
//do stuff
}
我想用一个模板化类(如 std::vector(来专门化它,所以像这样:
template<typename T>
int func(const std::vector<T>& input){
//do specialised stuff
}
但我不知道你到底是怎么做到的。谢谢!
继续
#include <vector>
#include <iostream>
using namespace std;
template<typename T>
int func(const vector<T>& a){
for(auto i: a) //do specialised stuff
cout<< (i<<1) <<"n";
return 0;
}
int main() {
vector<int> a={9,8,7};
func(a);
}
18
16
14
将每个阵列 A 乘以 2(左移一次,<<1(
相关文章:
- 尝试根据类中 typedef 的存在来专门化模板函数
- 如何基于模板化类的基类专门化成员函数
- 专门化模板覆盖函数/避免对象切片
- 如何使用模板化类专门化模板化函数?
- 线程 std::调用未知类型,无法专门化函数错误
- 如何在编译时专门化大型模板函数中的小部分
- 模板函数,其中一个参数需要专门化,而另一个不需要
- 错误 C2893 无法专门化函数模板'unknown-type std::invoke(_Callable &&,_Types &&...)'
- 从 std 命名空间中专门化函数模板的想法有多糟糕?
- 为模板函数专门化一个模板类
- 基于参数值的c++模板成员函数专门化
- 如何确定函数专门化的主模板
- 等价参数的c++函数专门化
- 基于运行时值调用不同的模板函数专门化
- 跨库的模板函数专门化符号匹配
- 模板函数专门化,c++
- 如何使用type_traits或模板函数专门化来整合模板方法
- 如何在子类中重载模板化函数(专门化)
- 可变模板函数:专门化头/尾和空基准情况
- 不允许void的部分函数专门化-替代解决方案