template non-type parameter 非类型参数
2015-03-31 16:44
447 查看
CUDA v6.5 sample->0_simple->matrixMul 中看到语法:
对于用法:
template <typename \ class>
是很常见的,但对于用法:
却少见。
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:
In fact, we can create algorithms which evaluate at compile time (from
Wikipedia):
使用 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
template <int BLOCK_SIZE> __global__ void matrixMulCUDA(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 == 1 void 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
相关文章推荐
- c++无类型参数模板(non-type template parameter)
- c++ template笔记(3)非类型模板参数nontype template parameters
- c++ template笔记(3)非类型模板参数nontype template parameters
- C++ - 非类型模板参数(nontype template parameters) 使用 及 代码
- C++ - 非类型模板参数(nontype template parameters) 使用 及 代码
- C++ - 非类型模板参数(nontype template parameters) 使用 及 代码
- Nontype Class Template Parameters(非类型类模板参数)
- SpringMVC 数组类型的参数: Cannot generate variable name for non-typed Collection parameter type
- 条款24:若所有参数皆需要类型转换,请为此采用non-member函数(Declare non-member functions when type conversions should apply to all parameters)
- 三、非类型模板参数(Nontype Template Parameters)
- MyBatis的传入参数parameterType类型
- MyBatis的传入参数parameterType类型
- SharePoint列表的模板类型中的BaseType参数和ListTemplate参数
- MyBatis的传入参数parameterType类型
- MyBatis中传入参数parameterType类型详解
- Nontype template parameter
- Nontype template parameters(非型别模板参数)
- MyBatis的传入参数parameterType类型
- MyBatis的传入参数parameterType类型
- MyBatis传入参数与parameterType不同类型使用