目 录
1 简介..................................................................................................................................................4
2 编程原则..........................................................................................................................................4
2.1 守卫(guard)头文件..........................................................................................................4
2.2 避免使用全局函数...............................................................................................................4
2.3 考虑用户名字空间...............................................................................................................6
2.4 使用 placement new 后,显式调用析构函数.....................................................................6
2.5 避免链式使用指针成员选择操作符(->).......................................................................7
2.6 避免直接调用系统函数.......................................................................................................7
2.7 运用统一的出错处理...........................................................................................................8
2.8 实现 dump()方法..................................................................................................................8
2.9 使用文件描述符抽象...........................................................................................................9
2.10 允许运行时跟踪.................................................................................................................9
2.11 检查所有的返回值...........................................................................................................10
2.12 限定(qualify)不在范围内的方法...............................................................................10
2.13 基类中避免出现数据成员...............................................................................................10
2.14 实现 open()/close()方法....................................................................................................11
3 编译器............................................................................................................................................11
3.1 避免直接使用 inline...........................................................................................................11
3.2 将模板和非模板分开.........................................................................................................13
3.3 在模板中使用 traits............................................................................................................14
3.4 用非模板类为基类.............................................................................................................15
3.5 守卫模板源文件.................................................................................................................15
4 配置................................................................................................................................................16
4.1 预防诡异的(quirky)编译器..........................................................................................16
4.2 通过特征描述平台(Specify a platform by its features)...............................................16
4.3 使用 config.h.......................................................................................................................17
5 初始化............................................................................................................................................18
5.1 在第一次使用时初始化.....................................................................................................18
5.2 避免创建静态对象.............................................................................................................18
5.3 确保单件的销毁.................................................................................................................19
6 模式实践........................................................................................................................................19
6.1 策略化内存分配.................................................................................................................19
6.2 应用策略模式.....................................................................................................................20
6.3 包装(wrapper)相同的函数............................................................................................21
6.4 用包装(wrapper)参数化组件........................................................................................21
6.5 实现迭代器.........................................................................................................................21
6.6 将创建和使用分离.............................................................................................................22
7 多线程............................................................................................................................................22
7.1 让所有方法可重入(reentrant).......................................................................................22
7.2 避免使用哨兵(sentinels)...............................................................................................22
7.3 用没有守卫(unguarded)的析构函数............................................................................25
7.4 守卫 open()/close()方法......................................................................................................25
7.5 用没有守卫(unguarded)的保护/私有方法...................................................................26