template non-type parameter 非类型参数
来源:互联网 发布:贴片机编程技术视频 编辑:程序博客网 时间:2024/05/18 02:46
CUDA v6.5 sample->0_simple->matrixMul 中看到语法:
template <int BLOCK_SIZE> __global__ voidmatrixMulCUDA(float *C, float *A, float *B, int wA, int wB){ // function body}
对于用法:
template <typename \ class>
是很常见的,但对于用法:
template <int >
却少见。
It's perfectly possible to template a class on an integer rather than a type. We can assign the templated value to a variable, or otherwise manipulate in a way we might with any other integer literal:
unsigned int x = N;
In fact, we can create algorithms which evaluate at compile time (from Wikipedia):
template <int N>struct Factorial { enum { value = N * Factorial<N - 1>::value };};template <>struct Factorial<0> { enum { value = 1 };};// Factorial<4>::value == 24// Factorial<0>::value == 1void foo(){ int x = Factorial<4>::value; // == 24 int y = Factorial<0>::value; // == 1}
使用 int 类型模板,可以在编译时确定。例如:
template<unsigned int S>struct Vector { unsigned char bytes[S];};// pass 3 as argument.Vector<3> test;
更多内容可参考: http://stackoverflow.com/questions/499106/what-does-template-unsigned-int-n-mean
http://stackoverflow.com/questions/24790287/templates-int-t-c
0 0
- template non-type parameter 非类型参数
- c++无类型参数模板(non-type template parameter)
- C++ non type template parameters
- Template template parameter(模板参数) example
- Nontype Class Template Parameters(非类型类模板参数)
- c++ template笔记(3)非类型模板参数nontype template parameters
- [翻译] Effective C++, 3rd Edition, Item 24: 当希望将 type conversions(类型转换)应用于所有 parameters(参数)时,请声明为 non-member functions(非成员函数)
- template template parameter
- C++ - 使用非成员函数(non-member)处理函数的所有参数都需要类型转换
- C++ - 非类型模板参数(nontype template parameters) 使用 及 代码
- C++ - 非类型模板参数(nontype template parameters) 使用 及 代码
- 模板非类型参数
- 非类型模板参数
- 非类型模板参数
- 非类型模板参数
- 非类型模板参数
- 非类型模版参数
- 非类型模板参数
- 【生活】程序员爱代码,而我爱你们
- UITextField监听文字输入事件
- 妙用html5的八大特性来开发移动webAPP
- 二维码的生成器。
- 带默认参数的函数
- template non-type parameter 非类型参数
- OVS学习总结---启动流程分析
- 3.3 Struts2的流程
- 东莞市盈辉汽车配件有限公司
- python-neutronclient架构分析
- UNIX socket编程(适用于iOS)
- Android之Android WebView常见问题及解决方案汇总
- dnsmasq服务
- 彻底解决_OBJC_CLASS_$_某文件名", referenced from:问题