Boost程序库完全开发指南――深入C++"准”标准库(第4版)
目录
第 0 章导读 .................................................... 1
0.1 关于本书........................................... 1
0.2 读者对象........................................... 1
0.3 术语与风格...................................... 2
0.4 语言标准...........................…
查看完整
第 0 章导读 .................................................... 1
0.1 关于本书........................................... 1
0.2 读者对象........................................... 1
0.3 术语与风格...................................... 2
0.4 语言标准...........................…
查看完整
罗剑锋(网名Chrono)在1996年就读于东北财经大学;1997年开始接触C/C++;1998年参加计算机软件专业技术资格和水平考试,获高级程序员资质;2003年毕业于北京理工大学,获计算机专业硕士学位。主要研究方向为C/C++、设计模式、高性能网络服务器开发,业余爱好是阅读、旅游、欣赏音乐和电影。
Boost 是一个功能强大、构造精巧、跨平台、开源并且完全免费的C++程序库,有着“C++‘准’标准库”的美誉。Boost 由C++标准委员会部分成员所设立的Boost 社区开发并维护,使用了许多现代C++编程技术,内容涵盖字符串处理、正则表达式、容器与数据结构、并发编程、函数式编程、泛型编程、设计模式实现等许多领域,极大地丰富了C++的功能和表现力,能够使C++软件开发更加简捷、优雅、灵活和高效。本书基于2017 年4 月发布的Boost1.64 版,介绍了其中的所有140 余个库,并且结合C++11/14/17标准详细、深入地讲解了其中数十个库,同时实现了若干颇具实用价值的工具类和函数,可帮助读者迅速地理解、掌握Boost 的用法并应用于实际的开发工作。本书内容丰富、结构严谨、详略得当、讲解透彻,带领读者领略了C++的*新前沿技术,相信会是每位C++程序员的必备工具书。
目录
第 0 章导读 .................................................... 1
0.1 关于本书........................................... 1
0.2 读者对象........................................... 1
0.3 术语与风格...................................... 2
0.4 语言标准........................................... 3
0.5 本书的结构...................................... 4
0.6 如何阅读本书.................................. 5
0.7 本书的源码...................................... 5
第 1 章总论 .................................................... 7
1.1 简介................................................... 7
1.1.1 获取方式................................. 8
1.1.2 目录结构................................. 8
1.1.3 使用方式................................. 9
1.2 开发环境........................................... 9
1.2.1 操作系统和编译器................10
1.2.2 快捷安装................................10
1.2.3 完全安装................................10
1.2.4 定制安装................................11
1.2.5 编译验证................................11
1.3 构建工具..........................................12
1.3.1 安装方式................................12
1.3.2 构建脚本................................12
1.3.3 构建语言...............................13
1.3.4 构建命令...............................14
1.4 总结..................................................14
第 2 章时间与日期......................................15
2.1 timer 库概述....................................15
2.2 timer .................................................16
2.2.1 用法.......................................16
2.2.2 类摘要...................................17
2.2.3 使用建议...............................18
2.3 progress_timer .................................18
2.3.1 用法.......................................18
2.3.2 类摘要...................................19
2.4 progress_display..............................19
2.4.1 类摘要...................................20
2.4.2 用法.......................................21
2.4.3 注意事项...............................22
2.5 date_time 库概述............................23
2.5.1 使用方式...............................23
2.5.2 基本概念...............................24
2.6 处理日期..........................................24
2.6.1 日期.......................................25
2.6.2 创建日期对象........................25
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
X
2.6.3 访问日期................................27
2.6.4 日期的输出............................28
2.6.5 转换C 结构...........................29
2.6.6 日期长度................................29
2.6.7 日期运算................................30
2.6.8 日期区间................................31
2.6.9 日期区间运算........................33
2.6.10 日期迭代器..........................34
2.6.11 其他功能..............................35
2.6.12 综合运用..............................36
2.7 处理时间..........................................38
2.7.1 时间长度................................39
2.7.2 操作时间长度........................40
2.7.3 时间精确度............................42
2.7.4 时间点...................................43
2.7.5 创建时间点对象....................44
2.7.6 操作时间点对象....................44
2.7.7 转换C 结构...........................45
2.7.8 时间区间................................46
2.7.9 时间迭代器............................46
2.7.10 综合运用..............................47
2.8 date_time 库的高级议题...............49
2.8.1 编译配置宏............................50
2.8.2 自定义字面值........................50
2.8.3 格式化时间............................51
2.8.4 本地时间................................51
2.9 总结..................................................53
第 3 章内存管理...........................................55
3.1 smart_ptr 库概述.............................55
3.1.1 RAII 机制..............................55
3.1.2 智能指针................................56
3.2 scoped_ptr ........................................57
3.2.1 类摘要...................................57
3.2.2 操作函数................................58
3.2.3 用法.......................................59
3.2.4 对比标准...............................61
3.3 shared_ptr ........................................63
3.3.1 类摘要...................................63
3.3.2 操作函数...............................64
3.3.3 用法.......................................65
3.3.4 工厂函数...............................67
3.3.5 应用于标准容器....................68
3.3.6 应用于桥接模式....................69
3.3.7 应用于工厂模式....................70
3.3.8 定制删除器............................72
3.3.9 高级议题...............................73
3.4 weak_ptr...........................................76
3.4.1 类摘要...................................76
3.4.2 用法.......................................77
3.4.3 对象自我管理........................78
3.4.4 打破循环引用........................79
3.5 intrusive_ptr.....................................80
3.5.1 类摘要...................................80
3.5.2 用法.......................................81
3.5.3 引用计数器............................82
3.6 pool 库概述.....................................83
3.7 pool...................................................83
3.7.1 类摘要...................................84
3.7.2 操作函数...............................84
3.7.3 用法.......................................85
3.8 object_pool ......................................86
3.8.1 类摘要...................................86
3.8.2 操作函数...............................86
3.8.3 用法.......................................87
3.8.4 更多的构造参数....................88
3.9 singleton_pool .................................89
3.9.1 类摘要...................................89
3.9.2 用法.......................................90
3.10 pool_alloc ......................................91
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XI
3.11 总结................................................91
第 4 章实用工具...........................................93
4.1 noncopyable.....................................93
4.1.1 原理.......................................94
4.1.2 用法.......................................94
4.1.3 实现.......................................95
4.2 ignore_unused..................................96
4.2.1 基本用法................................96
4.2.2 模板用法................................97
4.3 optional.............................................97
4.3.1 类摘要...................................98
4.3.2 操作函数................................99
4.3.3 用法.....................................100
4.3.4 工厂函数..............................101
4.4 assign..............................................102
4.4.1 list_inserter...........................102
4.4.2 operator+=............................103
4.4.3 operator () ............................104
4.4.4 generic_list...........................105
4.4.5 初始化容器..........................106
4.4.6 重复输入..............................108
4.4.7 操作非标准容器..................109
4.4.8 其他议题..............................110
4.5 tribool .............................................110
4.5.1 类摘要.................................110
4.5.2 用法.....................................111
4.5.3 为第三态更名......................112
4.5.4 输入/输出............................113
4.5.5 其他议题..............................113
4.6 operators.........................................114
4.6.1 基本运算概念......................116
4.6.2 算术操作符..........................116
4.6.3 基类链.................................118
4.6.4 复合运算概念......................119
4.6.5 相等与等价..........................121
4.6.6 解引用操作符......................122
4.6.7 下标操作符..........................123
4.6.8 布尔转型操作符..................124
4.6.9 二元操作符..........................126
4.7 exception........................................126
4.7.1 标准库中的异常..................127
4.7.2 类摘要.................................127
4.7.3 向异常传递信息..................129
4.7.4 错误信息类..........................130
4.7.5 包装标准异常......................132
4.7.6 使用函数抛出异常..............132
4.7.7 获得更多信息......................133
4.7.8 高级议题.............................134
4.8 uuid.................................................136
4.8.1 类摘要.................................136
4.8.2 用法.....................................137
4.8.3 生成器.................................139
4.8.4 增强用法.............................141
4.8.5 转换字符串..........................142
4.8.6 摘要算法.............................143
4.9 config..............................................144
4.9.1 编译期字符串化..................144
4.9.2 静态整型常量......................145
4.10 utility ............................................145
4.10.1 二进制常量........................146
4.10.2 调用函数名........................147
4.11 总结..............................................148
第 5 章字符串与文本处理.......................151
5.1 lexical_cast ....................................151
5.1.1 函数声明.............................152
5.1.2 用法.....................................152
5.1.3 错误处理.............................153
5.1.4 转换对象的要求..................154
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XII
5.1.5 应用于自定义类..................155
5.1.6 对比标准..............................156
5.2 format .............................................157
5.2.1 简单的例子..........................157
5.2.2 输入操作符..........................159
5.2.3 类摘要.................................160
5.2.4 格式化语法..........................161
5.2.5 性能优化..............................162
5.2.6 高级用法..............................162
5.3 string_ref ........................................164
5.3.1 类摘要.................................164
5.3.2 用法.....................................166
5.4 string_algo .....................................167
5.4.1 简单示例..............................168
5.4.2 算法概述..............................169
5.4.3 大小写转换..........................169
5.4.4 判断式(算法) ..................170
5.4.5 判断式(函数对象) ..........172
5.4.6 分类.....................................172
5.4.7 修剪.....................................173
5.4.8 查找.....................................174
5.4.9 替换与删除..........................176
5.4.10 分割...................................177
5.4.11 合并...................................179
5.4.12 查找(分割)迭代器.........179
5.5 xpressive.........................................181
5.5.1 使用方式..............................181
5.5.2 正则表达式简介..................182
5.5.3 类摘要.................................183
5.5.4 正则匹配..............................185
5.5.5 正则查找..............................187
5.5.6 正则替换..............................188
5.5.7 正则迭代..............................189
5.5.8 正则分词..............................190
5.5.9 高级议题..............................192
5.6 总结................................................194
第 6 章正确性与测试................................197
6.1 assert...............................................197
6.1.1 基本用法.............................197
6.1.2 禁用断言.............................198
6.1.3 扩展用法.............................199
6.2 static_assert ...................................200
6.2.1 定义.....................................201
6.2.2 用法.....................................201
6.2.3 使用建议.............................203
6.3 lightweight_test .............................203
6.3.1 测试断言.............................203
6.3.2 用法.....................................204
6.3.3 测试元编程..........................205
6.4 test ..................................................205
6.4.1 最小化测试..........................206
6.4.2 单元测试框架......................207
6.4.3 测试断言.............................208
6.4.4 测试主体.............................209
6.4.5 测试实例.............................210
6.4.6 测试夹具.............................212
6.4.7 测试日志.............................214
6.4.8 运行参数.............................215
6.4.9 高级议题.............................216
6.5 总结................................................219
第 7 章容器与数据结构............................221
7.1 array................................................221
7.1.1 类摘要.................................222
7.1.2 操作函数.............................222
7.1.3 用法.....................................223
7.1.4 能力限制.............................224
7.1.5 初始化.................................224
7.1.6 对比标准.............................225
7.2 dynamic_bitset ..............................225
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XIII
7.2.1 类摘要.................................226
7.2.2 创建与赋值..........................227
7.2.3 容器操作..............................228
7.2.4 基本运算..............................229
7.2.5 访问元素..............................230
7.2.6 类型转换..............................231
7.2.7 集合操作..............................232
7.2.8 综合运用..............................233
7.3 unordered .......................................234
7.3.1 散列集合简介......................234
7.3.2 散列集合的用法..................236
7.3.3 散列映射简介......................238
7.3.4 散列映射的用法..................239
7.3.5 高级议题..............................241
7.4 bimap ..............................................243
7.4.1 类摘要.................................243
7.4.2 基本用法..............................244
7.4.3 值的集合类型......................245
7.4.4 集合类型的用法..................246
7.4.5 使用标签类型......................247
7.4.6 使用assign 库......................249
7.4.7 查找与替换..........................249
7.4.8 投射.....................................251
7.4.9 高级议题..............................252
7.5 circular_buffer ...............................253
7.5.1 类摘要.................................253
7.5.2 用法.....................................254
7.5.3 环形结构..............................255
7.5.4 空间优化..............................256
7.6 tuple ................................................257
7.6.1 二元组.................................257
7.6.2 类摘要.................................258
7.6.3 创建与赋值..........................258
7.6.4 访问元素..............................260
7.6.5 比较操作..............................261
7.6.6 输入输出.............................261
7.6.7 连结变量.............................262
7.6.8 内部结构.............................263
7.6.9 使用访问者模式..................264
7.6.10 高级议题...........................266
7.7 any ..................................................269
7.7.1 类摘要.................................269
7.7.2 访问元素.............................270
7.7.3 用法.....................................271
7.7.4 简化操作.............................271
7.7.5 保存指针.............................272
7.7.6 输出.....................................273
7.7.7 高级议题.............................275
7.8 variant.............................................276
7.8.1 类摘要.................................276
7.8.2 访问元素.............................277
7.8.3 用法.....................................278
7.8.4 访问器.................................279
7.8.5 高级议题.............................281
7.9 multi_array.....................................283
7.9.1 类摘要.................................284
7.9.2 用法.....................................285
7.9.3 改变形状和大小..................287
7.9.4 创建子视图..........................287
7.9.5 适配普通数组......................289
7.9.6 高级议题.............................290
7.10 property_tree ...............................292
7.10.1 类摘要...............................293
7.10.2 读取配置信息....................294
7.10.3 写入配置信息....................296
7.10.4 更多用法...........................297
7.10.5 数据格式...........................298
7.10.6 高级议题...........................300
7.11 总结..............................................302
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XIV
第8 章算法 .................................................305
8.1 foreach............................................305
8.1.1 用法.....................................306
8.1.2 详细解说..............................307
8.1.3 更优雅的名字......................308
8.1.4 支持的序列类型..................308
8.1.5 存在的问题..........................309
8.2 minmax...........................................310
8.2.1 用法.....................................310
8.2.2 存在的问题..........................311
8.3 minmax_element ...........................311
8.3.1 基本用法..............................312
8.3.2 其他用法..............................312
8.4 algorithm........................................313
8.4.1 clamp ...................................313
8.4.2 clamp_range .........................314
8.4.3 hex/unhex.............................314
8.5 总结................................................316
第 9 章数学与数字....................................317
9.1 math.constants ...............................317
9.1.1 基本用法..............................318
9.1.2 高级用法..............................318
9.2 integer.............................................319
9.2.1 整数特征..............................319
9.2.2 标准整数类型......................320
9.2.3 整数类型模板类..................322
9.3 rational............................................325
9.3.1 类摘要.................................326
9.3.2 创建与赋值..........................327
9.3.3 基本运算..............................327
9.3.4 类型转换..............................328
9.3.5 输入输出..............................328
9.3.6 分子与分母..........................328
9.3.7 其他议题..............................329
9.4 ratio.................................................330
9.4.1 类摘要.................................330
9.4.2 用法.....................................331
9.4.3 数字单位.............................331
9.4.4 字符串表示..........................333
9.5 crc ...................................................333
9.5.1 类摘要.................................334
9.5.2 预定义的实现类..................334
9.5.3 用法.....................................335
9.6 random............................................336
9.6.1 随机数发生器......................336
9.6.2 随机数分布器......................338
9.6.3 变量发生器..........................343
9.6.4 产生随机数据块..................344
9.6.5 真随机数发生器..................345
9.7 总结................................................348
第 10 章操作系统相关..............................349
10.1 system...........................................349
10.1.1 错误值...............................350
10.1.2 错误类别...........................350
10.1.3 错误代码...........................352
10.1.4 错误异常...........................354
10.2 chrono...........................................354
10.2.1 时间长度...........................355
10.2.2 使用时间长度....................356
10.2.3 时钟...................................358
10.2.4 时间点...............................360
10.2.5 综合运用...........................361
10.3 cpu_timer .....................................363
10.3.1 时间类型...........................364
10.3.2 cpu_timer ...........................364
10.3.4 auto_cpu_timer...................366
10.3.5 定制输出格式....................367
10.4 filesystem.....................................368
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XV
10.4.1 类摘要...............................368
10.4.2 路径表示............................370
10.4.3 可移植的文件名................372
10.4.4 路径处理............................372
10.4.5 异常处理............................375
10.4.6 文件状态............................376
10.4.7 文件属性............................377
10.4.8 文件操作............................378
10.4.9 迭代目录............................379
10.4.10 实例1...............................382
10.4.11 实例2...............................383
10.4.12 实例3...............................385
10.4.13 文件流操作......................386
10.5 program_options .........................387
10.5.1 概述...................................387
10.5.3 选项值...............................389
10.5.4 选项描述器........................391
10.5.5 选项描述器的用法............392
10.5.6 分析器...............................394
10.5.7 存储器...............................395
10.5.8 位置选项值........................396
10.5.9 环境变量............................398
10.5.10 分组选项信息..................399
10.5.11 高级用法..........................401
10.6 总结..............................................404
第 11 章函数与回调..................................405
11.1 ref..................................................405
11.1.1 类摘要...............................406
11.1.2 基本用法............................407
11.1.3 工厂函数............................407
11.1.4 操作包装............................408
11.1.5 综合应用............................409
11.1.6 对比标准............................410
11.2 bind ...............................................411
11.2.1 工作原理...........................411
11.2.2 绑定普通函数....................413
11.2.3 绑定成员函数....................414
11.2.4 绑定成员变量....................415
11.2.5 绑定函数对象....................416
11.2.6 对比标准...........................416
11.2.7 高级议题...........................417
11.3 function ........................................421
11.3.1 类摘要...............................421
11.3.2 声明形式...........................422
11.3.3 操作函数...........................423
11.3.4 用法...................................424
11.3.5 使用ref 库.........................425
11.3.6 用于回调...........................426
11.3.7 对比auto............................428
11.3.8 对比std::function...............429
11.4 signals2 ........................................429
11.4.1 类摘要...............................430
11.4.2 操作函数...........................431
11.4.3 用法...................................432
11.4.4 返回值...............................434
11.4.5 合并器...............................434
11.4.6 管理信号连接....................436
11.4.7 更灵活的管理信号连接.....437
11.4.8 自动管理连接....................439
11.4.9 应用于观察者模式............441
11.4.10 高级议题..........................444
11.5 总结..............................................449
第 12 章并发编程......................................451
12.1 atomic...........................................451
12.1.1 类摘要...............................452
12.1.2 基本用法...........................454
12.1.3 整数用法...........................455
12.1.4 并发顺序一致性................456
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XVI
12.2 thread............................................458
12.2.1 mutex .................................459
12.2.2 lock_guard..........................461
12.2.3 unique_lock ........................463
12.2.4 lock adapter ........................465
12.2.5 thread .................................467
12.2.6 使用线程............................469
12.2.7 中断线程............................472
12.2.8 thread_group ......................475
12.2.9 call_once ............................476
12.2.10 condition_variable ............477
12.2.11 shared_mutex....................481
12.2.12 future................................483
12.2.13 shared_future ....................486
12.2.14 高级议题..........................487
12.3 asio................................................491
12.3.1 概述...................................491
12.3.2 信号...................................497
12.3.3 定时器...............................501
12.3.4 网络通信............................507
12.3.5 同步通信............................514
12.3.6 异步通信............................516
12.3.7 解析网络地址....................521
12.3.8 使用协程............................524
12.3.9 其他议题............................526
12.4 总结..............................................530
第 13 章组件速览......................................533
13.1 算法..............................................533
13.2 字符串和文本处理.....................534
13.3 容器与数据结构.........................535
13.4 迭代器..........................................536
13.5 函数对象与高级编程................536
13.6 泛型编程.....................................538
13.7 模板元编程.................................539
13.8 预处理元编程.............................540
13.9 并发编程.....................................540
13.10 数学与数字...............................541
13.11 输入输出...................................542
13.12 操作系统相关...........................543
13.13 语言特性模拟...........................543
13.14 杂项............................................544
13.15 总结............................................546
第 14 章设计模式......................................547
14.1 创建型模式.................................548
14.2 结构型模式.................................549
14.3 行为模式.....................................552
14.4 其他模式.....................................555
14.5 总结..............................................557
第 15 章结束语..........................................559
15.1 未臻完美.....................................559
15.2 锦上添花.....................................560
15.3 工夫在诗外.................................563
15.4 临别赠言.....................................564
附录A 推荐书目.........................................565
附录B 标准简述.........................................567
附录C 关键字浅谈..................................... 571
^ 收 起
第 0 章导读 .................................................... 1
0.1 关于本书........................................... 1
0.2 读者对象........................................... 1
0.3 术语与风格...................................... 2
0.4 语言标准........................................... 3
0.5 本书的结构...................................... 4
0.6 如何阅读本书.................................. 5
0.7 本书的源码...................................... 5
第 1 章总论 .................................................... 7
1.1 简介................................................... 7
1.1.1 获取方式................................. 8
1.1.2 目录结构................................. 8
1.1.3 使用方式................................. 9
1.2 开发环境........................................... 9
1.2.1 操作系统和编译器................10
1.2.2 快捷安装................................10
1.2.3 完全安装................................10
1.2.4 定制安装................................11
1.2.5 编译验证................................11
1.3 构建工具..........................................12
1.3.1 安装方式................................12
1.3.2 构建脚本................................12
1.3.3 构建语言...............................13
1.3.4 构建命令...............................14
1.4 总结..................................................14
第 2 章时间与日期......................................15
2.1 timer 库概述....................................15
2.2 timer .................................................16
2.2.1 用法.......................................16
2.2.2 类摘要...................................17
2.2.3 使用建议...............................18
2.3 progress_timer .................................18
2.3.1 用法.......................................18
2.3.2 类摘要...................................19
2.4 progress_display..............................19
2.4.1 类摘要...................................20
2.4.2 用法.......................................21
2.4.3 注意事项...............................22
2.5 date_time 库概述............................23
2.5.1 使用方式...............................23
2.5.2 基本概念...............................24
2.6 处理日期..........................................24
2.6.1 日期.......................................25
2.6.2 创建日期对象........................25
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
X
2.6.3 访问日期................................27
2.6.4 日期的输出............................28
2.6.5 转换C 结构...........................29
2.6.6 日期长度................................29
2.6.7 日期运算................................30
2.6.8 日期区间................................31
2.6.9 日期区间运算........................33
2.6.10 日期迭代器..........................34
2.6.11 其他功能..............................35
2.6.12 综合运用..............................36
2.7 处理时间..........................................38
2.7.1 时间长度................................39
2.7.2 操作时间长度........................40
2.7.3 时间精确度............................42
2.7.4 时间点...................................43
2.7.5 创建时间点对象....................44
2.7.6 操作时间点对象....................44
2.7.7 转换C 结构...........................45
2.7.8 时间区间................................46
2.7.9 时间迭代器............................46
2.7.10 综合运用..............................47
2.8 date_time 库的高级议题...............49
2.8.1 编译配置宏............................50
2.8.2 自定义字面值........................50
2.8.3 格式化时间............................51
2.8.4 本地时间................................51
2.9 总结..................................................53
第 3 章内存管理...........................................55
3.1 smart_ptr 库概述.............................55
3.1.1 RAII 机制..............................55
3.1.2 智能指针................................56
3.2 scoped_ptr ........................................57
3.2.1 类摘要...................................57
3.2.2 操作函数................................58
3.2.3 用法.......................................59
3.2.4 对比标准...............................61
3.3 shared_ptr ........................................63
3.3.1 类摘要...................................63
3.3.2 操作函数...............................64
3.3.3 用法.......................................65
3.3.4 工厂函数...............................67
3.3.5 应用于标准容器....................68
3.3.6 应用于桥接模式....................69
3.3.7 应用于工厂模式....................70
3.3.8 定制删除器............................72
3.3.9 高级议题...............................73
3.4 weak_ptr...........................................76
3.4.1 类摘要...................................76
3.4.2 用法.......................................77
3.4.3 对象自我管理........................78
3.4.4 打破循环引用........................79
3.5 intrusive_ptr.....................................80
3.5.1 类摘要...................................80
3.5.2 用法.......................................81
3.5.3 引用计数器............................82
3.6 pool 库概述.....................................83
3.7 pool...................................................83
3.7.1 类摘要...................................84
3.7.2 操作函数...............................84
3.7.3 用法.......................................85
3.8 object_pool ......................................86
3.8.1 类摘要...................................86
3.8.2 操作函数...............................86
3.8.3 用法.......................................87
3.8.4 更多的构造参数....................88
3.9 singleton_pool .................................89
3.9.1 类摘要...................................89
3.9.2 用法.......................................90
3.10 pool_alloc ......................................91
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XI
3.11 总结................................................91
第 4 章实用工具...........................................93
4.1 noncopyable.....................................93
4.1.1 原理.......................................94
4.1.2 用法.......................................94
4.1.3 实现.......................................95
4.2 ignore_unused..................................96
4.2.1 基本用法................................96
4.2.2 模板用法................................97
4.3 optional.............................................97
4.3.1 类摘要...................................98
4.3.2 操作函数................................99
4.3.3 用法.....................................100
4.3.4 工厂函数..............................101
4.4 assign..............................................102
4.4.1 list_inserter...........................102
4.4.2 operator+=............................103
4.4.3 operator () ............................104
4.4.4 generic_list...........................105
4.4.5 初始化容器..........................106
4.4.6 重复输入..............................108
4.4.7 操作非标准容器..................109
4.4.8 其他议题..............................110
4.5 tribool .............................................110
4.5.1 类摘要.................................110
4.5.2 用法.....................................111
4.5.3 为第三态更名......................112
4.5.4 输入/输出............................113
4.5.5 其他议题..............................113
4.6 operators.........................................114
4.6.1 基本运算概念......................116
4.6.2 算术操作符..........................116
4.6.3 基类链.................................118
4.6.4 复合运算概念......................119
4.6.5 相等与等价..........................121
4.6.6 解引用操作符......................122
4.6.7 下标操作符..........................123
4.6.8 布尔转型操作符..................124
4.6.9 二元操作符..........................126
4.7 exception........................................126
4.7.1 标准库中的异常..................127
4.7.2 类摘要.................................127
4.7.3 向异常传递信息..................129
4.7.4 错误信息类..........................130
4.7.5 包装标准异常......................132
4.7.6 使用函数抛出异常..............132
4.7.7 获得更多信息......................133
4.7.8 高级议题.............................134
4.8 uuid.................................................136
4.8.1 类摘要.................................136
4.8.2 用法.....................................137
4.8.3 生成器.................................139
4.8.4 增强用法.............................141
4.8.5 转换字符串..........................142
4.8.6 摘要算法.............................143
4.9 config..............................................144
4.9.1 编译期字符串化..................144
4.9.2 静态整型常量......................145
4.10 utility ............................................145
4.10.1 二进制常量........................146
4.10.2 调用函数名........................147
4.11 总结..............................................148
第 5 章字符串与文本处理.......................151
5.1 lexical_cast ....................................151
5.1.1 函数声明.............................152
5.1.2 用法.....................................152
5.1.3 错误处理.............................153
5.1.4 转换对象的要求..................154
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XII
5.1.5 应用于自定义类..................155
5.1.6 对比标准..............................156
5.2 format .............................................157
5.2.1 简单的例子..........................157
5.2.2 输入操作符..........................159
5.2.3 类摘要.................................160
5.2.4 格式化语法..........................161
5.2.5 性能优化..............................162
5.2.6 高级用法..............................162
5.3 string_ref ........................................164
5.3.1 类摘要.................................164
5.3.2 用法.....................................166
5.4 string_algo .....................................167
5.4.1 简单示例..............................168
5.4.2 算法概述..............................169
5.4.3 大小写转换..........................169
5.4.4 判断式(算法) ..................170
5.4.5 判断式(函数对象) ..........172
5.4.6 分类.....................................172
5.4.7 修剪.....................................173
5.4.8 查找.....................................174
5.4.9 替换与删除..........................176
5.4.10 分割...................................177
5.4.11 合并...................................179
5.4.12 查找(分割)迭代器.........179
5.5 xpressive.........................................181
5.5.1 使用方式..............................181
5.5.2 正则表达式简介..................182
5.5.3 类摘要.................................183
5.5.4 正则匹配..............................185
5.5.5 正则查找..............................187
5.5.6 正则替换..............................188
5.5.7 正则迭代..............................189
5.5.8 正则分词..............................190
5.5.9 高级议题..............................192
5.6 总结................................................194
第 6 章正确性与测试................................197
6.1 assert...............................................197
6.1.1 基本用法.............................197
6.1.2 禁用断言.............................198
6.1.3 扩展用法.............................199
6.2 static_assert ...................................200
6.2.1 定义.....................................201
6.2.2 用法.....................................201
6.2.3 使用建议.............................203
6.3 lightweight_test .............................203
6.3.1 测试断言.............................203
6.3.2 用法.....................................204
6.3.3 测试元编程..........................205
6.4 test ..................................................205
6.4.1 最小化测试..........................206
6.4.2 单元测试框架......................207
6.4.3 测试断言.............................208
6.4.4 测试主体.............................209
6.4.5 测试实例.............................210
6.4.6 测试夹具.............................212
6.4.7 测试日志.............................214
6.4.8 运行参数.............................215
6.4.9 高级议题.............................216
6.5 总结................................................219
第 7 章容器与数据结构............................221
7.1 array................................................221
7.1.1 类摘要.................................222
7.1.2 操作函数.............................222
7.1.3 用法.....................................223
7.1.4 能力限制.............................224
7.1.5 初始化.................................224
7.1.6 对比标准.............................225
7.2 dynamic_bitset ..............................225
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XIII
7.2.1 类摘要.................................226
7.2.2 创建与赋值..........................227
7.2.3 容器操作..............................228
7.2.4 基本运算..............................229
7.2.5 访问元素..............................230
7.2.6 类型转换..............................231
7.2.7 集合操作..............................232
7.2.8 综合运用..............................233
7.3 unordered .......................................234
7.3.1 散列集合简介......................234
7.3.2 散列集合的用法..................236
7.3.3 散列映射简介......................238
7.3.4 散列映射的用法..................239
7.3.5 高级议题..............................241
7.4 bimap ..............................................243
7.4.1 类摘要.................................243
7.4.2 基本用法..............................244
7.4.3 值的集合类型......................245
7.4.4 集合类型的用法..................246
7.4.5 使用标签类型......................247
7.4.6 使用assign 库......................249
7.4.7 查找与替换..........................249
7.4.8 投射.....................................251
7.4.9 高级议题..............................252
7.5 circular_buffer ...............................253
7.5.1 类摘要.................................253
7.5.2 用法.....................................254
7.5.3 环形结构..............................255
7.5.4 空间优化..............................256
7.6 tuple ................................................257
7.6.1 二元组.................................257
7.6.2 类摘要.................................258
7.6.3 创建与赋值..........................258
7.6.4 访问元素..............................260
7.6.5 比较操作..............................261
7.6.6 输入输出.............................261
7.6.7 连结变量.............................262
7.6.8 内部结构.............................263
7.6.9 使用访问者模式..................264
7.6.10 高级议题...........................266
7.7 any ..................................................269
7.7.1 类摘要.................................269
7.7.2 访问元素.............................270
7.7.3 用法.....................................271
7.7.4 简化操作.............................271
7.7.5 保存指针.............................272
7.7.6 输出.....................................273
7.7.7 高级议题.............................275
7.8 variant.............................................276
7.8.1 类摘要.................................276
7.8.2 访问元素.............................277
7.8.3 用法.....................................278
7.8.4 访问器.................................279
7.8.5 高级议题.............................281
7.9 multi_array.....................................283
7.9.1 类摘要.................................284
7.9.2 用法.....................................285
7.9.3 改变形状和大小..................287
7.9.4 创建子视图..........................287
7.9.5 适配普通数组......................289
7.9.6 高级议题.............................290
7.10 property_tree ...............................292
7.10.1 类摘要...............................293
7.10.2 读取配置信息....................294
7.10.3 写入配置信息....................296
7.10.4 更多用法...........................297
7.10.5 数据格式...........................298
7.10.6 高级议题...........................300
7.11 总结..............................................302
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XIV
第8 章算法 .................................................305
8.1 foreach............................................305
8.1.1 用法.....................................306
8.1.2 详细解说..............................307
8.1.3 更优雅的名字......................308
8.1.4 支持的序列类型..................308
8.1.5 存在的问题..........................309
8.2 minmax...........................................310
8.2.1 用法.....................................310
8.2.2 存在的问题..........................311
8.3 minmax_element ...........................311
8.3.1 基本用法..............................312
8.3.2 其他用法..............................312
8.4 algorithm........................................313
8.4.1 clamp ...................................313
8.4.2 clamp_range .........................314
8.4.3 hex/unhex.............................314
8.5 总结................................................316
第 9 章数学与数字....................................317
9.1 math.constants ...............................317
9.1.1 基本用法..............................318
9.1.2 高级用法..............................318
9.2 integer.............................................319
9.2.1 整数特征..............................319
9.2.2 标准整数类型......................320
9.2.3 整数类型模板类..................322
9.3 rational............................................325
9.3.1 类摘要.................................326
9.3.2 创建与赋值..........................327
9.3.3 基本运算..............................327
9.3.4 类型转换..............................328
9.3.5 输入输出..............................328
9.3.6 分子与分母..........................328
9.3.7 其他议题..............................329
9.4 ratio.................................................330
9.4.1 类摘要.................................330
9.4.2 用法.....................................331
9.4.3 数字单位.............................331
9.4.4 字符串表示..........................333
9.5 crc ...................................................333
9.5.1 类摘要.................................334
9.5.2 预定义的实现类..................334
9.5.3 用法.....................................335
9.6 random............................................336
9.6.1 随机数发生器......................336
9.6.2 随机数分布器......................338
9.6.3 变量发生器..........................343
9.6.4 产生随机数据块..................344
9.6.5 真随机数发生器..................345
9.7 总结................................................348
第 10 章操作系统相关..............................349
10.1 system...........................................349
10.1.1 错误值...............................350
10.1.2 错误类别...........................350
10.1.3 错误代码...........................352
10.1.4 错误异常...........................354
10.2 chrono...........................................354
10.2.1 时间长度...........................355
10.2.2 使用时间长度....................356
10.2.3 时钟...................................358
10.2.4 时间点...............................360
10.2.5 综合运用...........................361
10.3 cpu_timer .....................................363
10.3.1 时间类型...........................364
10.3.2 cpu_timer ...........................364
10.3.4 auto_cpu_timer...................366
10.3.5 定制输出格式....................367
10.4 filesystem.....................................368
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XV
10.4.1 类摘要...............................368
10.4.2 路径表示............................370
10.4.3 可移植的文件名................372
10.4.4 路径处理............................372
10.4.5 异常处理............................375
10.4.6 文件状态............................376
10.4.7 文件属性............................377
10.4.8 文件操作............................378
10.4.9 迭代目录............................379
10.4.10 实例1...............................382
10.4.11 实例2...............................383
10.4.12 实例3...............................385
10.4.13 文件流操作......................386
10.5 program_options .........................387
10.5.1 概述...................................387
10.5.3 选项值...............................389
10.5.4 选项描述器........................391
10.5.5 选项描述器的用法............392
10.5.6 分析器...............................394
10.5.7 存储器...............................395
10.5.8 位置选项值........................396
10.5.9 环境变量............................398
10.5.10 分组选项信息..................399
10.5.11 高级用法..........................401
10.6 总结..............................................404
第 11 章函数与回调..................................405
11.1 ref..................................................405
11.1.1 类摘要...............................406
11.1.2 基本用法............................407
11.1.3 工厂函数............................407
11.1.4 操作包装............................408
11.1.5 综合应用............................409
11.1.6 对比标准............................410
11.2 bind ...............................................411
11.2.1 工作原理...........................411
11.2.2 绑定普通函数....................413
11.2.3 绑定成员函数....................414
11.2.4 绑定成员变量....................415
11.2.5 绑定函数对象....................416
11.2.6 对比标准...........................416
11.2.7 高级议题...........................417
11.3 function ........................................421
11.3.1 类摘要...............................421
11.3.2 声明形式...........................422
11.3.3 操作函数...........................423
11.3.4 用法...................................424
11.3.5 使用ref 库.........................425
11.3.6 用于回调...........................426
11.3.7 对比auto............................428
11.3.8 对比std::function...............429
11.4 signals2 ........................................429
11.4.1 类摘要...............................430
11.4.2 操作函数...........................431
11.4.3 用法...................................432
11.4.4 返回值...............................434
11.4.5 合并器...............................434
11.4.6 管理信号连接....................436
11.4.7 更灵活的管理信号连接.....437
11.4.8 自动管理连接....................439
11.4.9 应用于观察者模式............441
11.4.10 高级议题..........................444
11.5 总结..............................................449
第 12 章并发编程......................................451
12.1 atomic...........................................451
12.1.1 类摘要...............................452
12.1.2 基本用法...........................454
12.1.3 整数用法...........................455
12.1.4 并发顺序一致性................456
目录
Boost 程序库完全开发指南―深入C++“准”标准库(第4 版)
XVI
12.2 thread............................................458
12.2.1 mutex .................................459
12.2.2 lock_guard..........................461
12.2.3 unique_lock ........................463
12.2.4 lock adapter ........................465
12.2.5 thread .................................467
12.2.6 使用线程............................469
12.2.7 中断线程............................472
12.2.8 thread_group ......................475
12.2.9 call_once ............................476
12.2.10 condition_variable ............477
12.2.11 shared_mutex....................481
12.2.12 future................................483
12.2.13 shared_future ....................486
12.2.14 高级议题..........................487
12.3 asio................................................491
12.3.1 概述...................................491
12.3.2 信号...................................497
12.3.3 定时器...............................501
12.3.4 网络通信............................507
12.3.5 同步通信............................514
12.3.6 异步通信............................516
12.3.7 解析网络地址....................521
12.3.8 使用协程............................524
12.3.9 其他议题............................526
12.4 总结..............................................530
第 13 章组件速览......................................533
13.1 算法..............................................533
13.2 字符串和文本处理.....................534
13.3 容器与数据结构.........................535
13.4 迭代器..........................................536
13.5 函数对象与高级编程................536
13.6 泛型编程.....................................538
13.7 模板元编程.................................539
13.8 预处理元编程.............................540
13.9 并发编程.....................................540
13.10 数学与数字...............................541
13.11 输入输出...................................542
13.12 操作系统相关...........................543
13.13 语言特性模拟...........................543
13.14 杂项............................................544
13.15 总结............................................546
第 14 章设计模式......................................547
14.1 创建型模式.................................548
14.2 结构型模式.................................549
14.3 行为模式.....................................552
14.4 其他模式.....................................555
14.5 总结..............................................557
第 15 章结束语..........................................559
15.1 未臻完美.....................................559
15.2 锦上添花.....................................560
15.3 工夫在诗外.................................563
15.4 临别赠言.....................................564
附录A 推荐书目.........................................565
附录B 标准简述.........................................567
附录C 关键字浅谈..................................... 571
^ 收 起
罗剑锋(网名Chrono)在1996年就读于东北财经大学;1997年开始接触C/C++;1998年参加计算机软件专业技术资格和水平考试,获高级程序员资质;2003年毕业于北京理工大学,获计算机专业硕士学位。主要研究方向为C/C++、设计模式、高性能网络服务器开发,业余爱好是阅读、旅游、欣赏音乐和电影。
Boost 是一个功能强大、构造精巧、跨平台、开源并且完全免费的C++程序库,有着“C++‘准’标准库”的美誉。Boost 由C++标准委员会部分成员所设立的Boost 社区开发并维护,使用了许多现代C++编程技术,内容涵盖字符串处理、正则表达式、容器与数据结构、并发编程、函数式编程、泛型编程、设计模式实现等许多领域,极大地丰富了C++的功能和表现力,能够使C++软件开发更加简捷、优雅、灵活和高效。本书基于2017 年4 月发布的Boost1.64 版,介绍了其中的所有140 余个库,并且结合C++11/14/17标准详细、深入地讲解了其中数十个库,同时实现了若干颇具实用价值的工具类和函数,可帮助读者迅速地理解、掌握Boost 的用法并应用于实际的开发工作。本书内容丰富、结构严谨、详略得当、讲解透彻,带领读者领略了C++的*新前沿技术,相信会是每位C++程序员的必备工具书。
比价列表