C++模板:完全指南
目录
前言
致谢第二版
致谢第一版
关于此书
阅读此书之前
阅览
阅读方式
编程评注
C++11,14,17标准
代码示例与其他信息
反馈
第一部分 基础
1 函数模板
1.1首个函数模板
1.1.1定义模板
1.1.2使用模板
1.1.3两阶段转变
1.2 模板参数推断
1.3多元模板参数
1.3.1模板参数返回值
1.3.2推断返回类型
1.3.3返回类型作为普通类型
1.4默认模板参数
1.5重载函数模板
1.6不能做…
1.6.1值传递,引用传递
1.6.2为什么不使用内联
1.6.3为什么不使用常量表达式
2 类模板
2.1栈-类模板实现
2.1.1类模板声明
2.1.2成员函数实现
2.2栈-类模板使用
2.3类模板具体使用
2.3.1概念
2.4友元
2.5类模板的原型
2.6原型点
2.7默认类模板参数
2.8类型别名
2.9类模板参数推断
2.10模板聚合
2.11总结
3 无类型模板参数
3.1五类型模板参数
3.2五类型函数模板参数
3.3无类型模板参数限制
3.4auto-模板参数类型
3.5总结
4 可变模板
4.1可变模板
4.1.1可变模板实例
4.1.2重载变量和无变量模板
4.1.3操作符sizeof
4.2折叠表达式
4.3变量模板应用
4.4可变类模板和变量表达式
4.4.1可变量表达式
4.4.2可变说明
4.4.3可变类型模板
4.4.4可变推断指南
可变基类和using
4.5总结
5 复杂基础
5.1关键字typename
5.2初始化
5.3使用this—>
5.4模板Array和String
5.5成员模板
5.5.1 .template结构
5.5.2通用Lambda和成员函数
5.6可变模板
5.7模板参数
5.8总结
6 移动语义和enable_if<>
6.1完美转发
6.2特殊成员函数模板
6.3非模板enable_if<>
6.4使用enable_if<>
6.5enable_if<>表达式
6.6总结
7 值或引用
7.1值传递
7.2引用传递
7.2.1常量引用传递
7.2.2非常量引用传递
7.2.3完美引用传递
7.3使用std::ref()和std::cref()
7.4处理string和array
7.4.1特殊实现-string和array
7.5处理返回值
7.6建议模板参数声明
7.7总结
8 编译时编程
8.1模板元编程
8.2使用constexpr
8.3执行路径选择具体化
8.4SFINAE
8.4.1表达式decltype
8.5编译时if
8.6总结
9 实践使用模板
9.1包含模式
9.1.1链接错误
9.1.2头文件中模板
9.2模板和inline
9.3预编译头文件
9.4编码错误级别
9.5afternotes
9.6总结
10 基础模板术语
10.1类模板或模板类
10.2代替,安装,专门化
10.3声明,定义
10.3.1完整与非完整类型
10.4定义规则
10.5模板参数对模板参数
10.6总结
11 通用库
11.1Callables
11.1.1支持函数对象
11.1.2处理成员函数和额外参数
11.1.3封装函数调用
11.2其他多功能实现库
11.2.1类型诊断
11.2.2std::addressof()
11.2.3std::declval()
11.3完美转换模板
11.4模板参数引用
11.5委托赋值
11.6考虑写通用库
11.7总结
第二部分 深入模板
12 深入原理
12.1参数声明
12.1.1虚成员函数
12.1.2模板链接
12.1.3重要模板
12.2模板实参
12.2.1类型参数
12.2.2无类型参数
12.2.3模板参数
12.2.4模板参数包
12.2.5默认模板参数
12.3模板形参
12.3.1函数模板形参
12.3.2类型形参
12.3.3无类型形参
12.3.4模板形参
12.3.5赋值
12.4可变模板
12.4.1包扩展
12.4.2包扩展产生之处
12.4.3函数模板参数包
12.4.4多元和嵌套包扩展
12.4.5 零长度包扩展
12.4.6折叠扩展
12.5友元
12.5.1类模板的友元类
12.5.2类模板的友元函数
12.5.3友元模板
12.6afternotes
13 模板名
13.1名字分类
13.2查找名字
13.2.1参数依赖查找
13.2.2参数以来查找之友元声明
13.2.3添加类名
13.2.4当前实例
13.3分析模板
13.3.1无模板文本意义
13.3.2类型依赖名
13.3.3模板依赖名
13.3.4使用声明依赖名
13.3.5ADL和显示模板参数
13.3.6依赖表达式
13.3.7编译错误
13.4继承和类模板
13.4.1无依赖基类
13.4.2依赖基类
13.5Afternotes
14 实例化
14.1需求实例化
14.2Lazy实例化
14.2.1部分和完全实例化
14.2.2实例化组件
14.3C++实例化模型
14.3.1两队查找
14.3.2实例化点
14.3.3包含模型
14.4实现项目
14.4.1贪婪实例化
14.4.2查找实例化
14.4.3迭代实例化
14.5显示实例化
14.5.1手动实例化
14.5.2显示实例化声明
14.6编译时if语句
14.7标准库
14.8Afternotes
15模板形参推断
15.1推断处理
15.2推断文本
15.3特别推断情境
15.4初始化列表
15.5参数包
15.5.1字面操作模板
15.6右值引用
15.6.1引用折叠原则
15.6.2转换引用
15.6.3完美转换
15.6.4推断出现
15.7AFINAE
15.7.1即刻文本
15.8限制推断
15.8.1允许参数转换
15.8.2类模板参数
15.8.3默认调用参数
15.8.4异常情况
15.9显示函数模板参数
15.10推断初始化和表达式
15.10.1auto类型特例
15.10.2decltype类型
15.10.3decltype(auto)
15.10.4auto特例化之特殊化
15.10.5结构绑定
15.10.6通用Lambda
15.11别名模板
15.12类模板参数推断
15.12.1推断指南
15.12.2隐式推断指南
15.12.3其他情况
15.13Afternotes
16 特例化与重载
16.1通用编码不能退出
16.1.1转换化
16.1.2
17 发展方向
第三部分 模板和设计
18 模板的多态化
19 实现诊断
20 重载类型属性
21 模板和继承
22 衔接静态和动态多态
23 多态编程
24 类型化
25 元组
26 区分联合
27 表达式模板
28 调试模板
附录
#include<iostream> int main() { return 0; }