- 浏览: 202732 次
- 性别:
- 来自: 重庆
文章分类
最新评论
template <unsigned int N>
- 博客分类:
- c++
详见:http://stackoverflow.com/questions/499106/what-does-template-unsigned-int-n-mean
You can have several kinds of template parameters
Type Parameters.
Types
Templates (only classes, no functions)
Non-type Parameters
Pointers
References
Integral constant expressions
What you have there is of the last kind. It's a compile time constant (so-called constant expression) and is of type integer or enumeration. After looking it up in the standard, i had to move class templates up into the types section - even though templates are not types. But they are called type-parameters for the purpose of describing those kinds nonetheless. You can have pointers (and also member pointers) and references to objects/functions that have external linkage (those that can be linked to from other object files and whose address is unique in the entire program). Examples:
Template type parameter:
template<typename T>
struct Container {
T t;
};
// pass type "long" as argument.
Container<long> test;
Template integer parameter:
template<unsigned int S>
struct Vector {
unsigned char bytes[S];
};
// pass 3 as argument.
Vector<3> test;
Template pointer parameter (passing a pointer to a function)
template<void (*F)()>
struct FunctionWrapper {
static void call_it() { F(); }
};
// pass address of function do_it as argument.
void do_it() { }
FunctionWrapper<&do_it> test;
Template reference parameter (passing an integer)
template<int &A>
struct SillyExample {
static void do_it() { A = 10; }
};
// pass flag as argument
int flag;
SillyExample<flag> test;
Template template parameter.
template<template<typename T> class AllocatePolicy>
struct Pool {
void allocate(size_t n) {
int *p = AllocatePolicy<int>::allocate(n);
}
};
// pass the template "allocator" as argument.
template<typename T>
struct allocator { static T * allocate(size_t n) { return 0; } };
Pool<allocator> test;
A template without any parameters is not possible. But a template without any explicit argument is possible - it has default arguments:
template<unsigned int SIZE = 3>
struct Vector {
unsigned char buffer[SIZE];
};
Vector<> test;
Syntactically, template<> is reserved to mark an explicit template specialization, instead of a template without parameters:
template<>
struct Vector<3> {
// alternative definition for SIZE == 3
};
发表评论
-
C++的原子操作
2012-12-20 17:43 4657在多进程(线程)访问资源时,能够确保所有其他的进程(线程 ... -
匿名namespace的作用以及它与static的区别
2012-12-20 17:24 1771一。匿名namespace的作用 在C语言中,如果我们 ... -
C++类型萃取技术
2012-12-19 15:16 1116Traits技术可以用来获得一个 类型 的相关信息的。 ... -
数值压缩存储方法Varint
2012-12-19 14:35 817转自:http://www.cnblogs.com/smark ... -
TypeList
2012-12-19 13:49 1120转自:http://blog.csdn.n ... -
二维指针*(void **)的研究(uC/OS-II案例)
2012-12-19 22:20 3257原文 : http://blog.csdn ... -
多级指针和链表
2012-12-18 22:28 0如果看到一个声明:t ... -
理解*(void**)b
2012-12-18 22:03 0#include <stdio.h> ... -
STL标准库:Allocator能做什么
2012-12-18 20:10 0The Standard Librarian: Wha ... -
三种的allocator实现源代码的对比
2012-12-18 19:55 1286转自:http://blog.csdn.net ... -
结构体内变量相对便宜与list_entry()宏
2012-12-18 17:59 906#define list_entry(ptr, t ... -
声明与函数、函数指针---(*(void (*)( ) )0)( ) 解析
2012-12-18 17:33 1083概述 在很 ... -
c++模板(类型依赖)说明例子
2012-12-18 16:57 1130#include <iostream> # ... -
C++中三种new的用法
2012-12-18 16:44 1815我评价自己的C++水平还未入门的确不够准确,应该是远远未 ... -
C++,永久改变你写异常安全代码的方式(神奇的Loki::ScopeGuard)
2012-12-17 20:19 2483作者:Andrei Alexandrescu and P ... -
C++的make_pair函数
2012-12-17 17:19 3435Pairs C++标准程序库中凡是“必须返回两 ... -
C++的explicit构造函数
2012-12-13 15:59 626按照默认规定,只有一个参数的构造函数也定义了一个隐式转换 ...
相关推荐
reinterpret_cast<const unsigned char *>(_First), _Count * sizeof(_Kty))); } /*hash_val(string)*/ template<class _Elem, class _Traits, class _Alloc> inline size_t hash_val(const basic_string<_...
<td class=b><select name=fid><option value='-1'>所有版块</option>$forumcache</select></td></tr> 三行的下面增加 <!-- EOT; if($p_table){ print <<<EOT --> <tr><td class=b>分表数据库</td> ...
它支持以下功能:(T:float / double) // dst[i] += c * src[i]template<typename>void muladd(const T* src, T c, unsigned int size, T* dst)// dst = sum(s1[i] * s2[i])template<typename>T dot(const T* s1, ...
dev->dev_act[input_num].addr = (unsigned short)(dev->ccm_cfg[input_num]->act_slave>>1); strcpy(dev->dev_act[input_num].type,dev->ccm_cfg[input_num]->act_name); if(vfe_actuator_subdev_register...
dev->dev_act[input_num].addr = (unsigned short)(dev->ccm_cfg[input_num]->act_slave>>1); strcpy(dev->dev_act[input_num].type,dev->ccm_cfg[input_num]->act_name); if(vfe_actuator_subdev_register...
template<> inline UINT AFXAPI HashKey(CString & strGuid) { return HashKey( (LPCTSTR) strGuid); } #include "Mapper.h" typedef void (CALLBACK* NOTIFYPROC)(LPVOID, ClientContext*, UINT nCode); ...
template<T> T* mymalloc(unsigned nBytes); void myfree(void); void bye(void); /***************************************[progStart]*******************************************/ /*启动程序,创建息队例,...
/简单的字符串hash/unsigned int hash = 0;return (hash & 0x7FFFFFFF);
... job.php,read.php,show.php,setforum.php,postupload.php,template.php,setforum.htm 1. 数据库升级 进入phpMyAdmin -> SQL... <td><select name="remoteftp">$ftpselect</select></td> </tr> (完成...)
#include <afxres.h> // standard resource IDs #endif #ifndef __AFXCOLL_H__ #include <afxcoll.h> // standard collections #endif #ifdef _AFX_MINREBUILD #pragma component(minrebuild, off) #endif #...
" " " " " " "2 "placename "char(50) "NO " "" 广告位名称 " "3 "template "char(30) "NO " "0 " 模板 " "4 "introduce "char(100) "NO " "" 广告位介绍 " "5 "price "mediumint(8) unsigned "NO " "0 " 广告价格 ...
void resize( int new-ncols, int new-nrows) ; friend Mat rixT emplate3T4 operator * ( Mat rixTemplate3T4 & , Mat rixTemplate3T4 & ) ; friend VectorTemplate3T4 operator * ( MatrixTemplate3T4 & , ...
(159, '首页左侧广告', 216, 172, '', '<table cellpadding="0" cellspacing="0">\r\n{foreach from=$ads item=ad}\r\n<tr><td>{$ad}</td></tr>\r\n{/foreach}\r\n</table>'); -- --------------------------------...
The format of the symbol name should be <PROJECT>_<PATH>_<FILE>_H_. To guarantee uniqueness, they should be based on the full path in a project's source tree. For example, the file foo/src/bar/baz.h...
state.h包含一个琐碎的模板,用于包装unsigned int来形成机器状态。 还定义了HALT 。 colour.h是另一个包装char的琐碎模板:这些char代表各种磁带单元的颜色。 EMPTY在这里定义。 direction.h定义了三种类型: go...
返回值类型是C++中定义函数的必备部分,这些修饰符包括void,(unsigned) int,bool等内置基本数据类型和自定义类型,也包括修饰返回值const关键字(如const int*),还包括C++11中新增的类型自动推导auto关键字。...
auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while ...
goto if inline int long mutable namespace new operator private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try type_...
int long mutable namespace new operator private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try type_info typedef ...
• Tablets often control the system cursor, provide additional digitizing input, and provide template or macro functions. 1.2 The Windows Environment Programming for tablets in the Windows ...