10.1.3 从小部分人出发而瞄准的用户群体真的能够带来较大的商业价值吗?

GreyZeng 2021-08-07 15:52:53

原文地址

我们宁可从小部分人出发,要非常明确地定义谁是我们的用户。——10.1.3 怎样定义典型用户

​ 我赞成作者所说的软件不是为所有人服务的,那么考虑用户群体就是一个非常重要的问题。一款软件,一款带有商业和盈利性质的软件,从商业的角度来看,当然是用户群体处于一个较广阔的范围最好,以保证最大的收益。即使是一款针对特定用户群体的软件,用户群体有一定的范围,但是我认为也不至于到作者所说的小部分人的程度吧。毕竟软件的评价包括这款软件的商业价值,从小部分人出发而瞄准的用户群体真的能够带来较大的商业价值吗?

...全文
412 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
GreyZeng 2021-08-07
  • 打赏
  • 举报
回复

这个问题在当初已经有了部分解答,过于钻字眼,导致对“小”这个词的理解过于局限。如何理解“小”就是回答这个问题的关键。此处的“小”应该是相对于市场上所有的软件用户而言。由于软件的应用定位决定了不太可能是市场全部的用户,因此着眼于真正对这款软件有需求的用户、对此软件功能有潜在需求的用户就是最重要的一点,也即相比于市场上所有的用户而言,真正可能使用这款软件的“小”部分用户是最重要,即典型用户。根据团队项目实践结果来看,最终使用我们软件的用户也符合我们最终所分析的典型用户人群。
原文地址

仅收录该书籍以供学习和讨论 包含pdf书籍及经过验证的示例 执行demo中的示例方式 在编译环境下进入demo目录,执行nmake命令在bin目录下生成可执行文件 注:demo无注释,对应书本中部分示例。 目录 第1章 Windows应用程序开发入门 1 1.1 第一个实例程序 1 1.1.1 start.exe 1 1.1.2 Windows API 2 1.1.3 程序入口函数 2 1.1.4 start.c代码分析 2 1.2 编译代码 3 1.2.1 安装Visual Studio 3 1.2.2 安装Microsoft Platform SDK 4 1.2.3 集成Microsoft Platform SDK与Visual C++速成版 5 1.2.4 Vista SDK与Visual Studio 2008 6 1.2.5 Visual Studio专业版或团队系统版 7 1.2.6 使用图形化IDE建立工程、进行编译 7 1.2.7 “解决方案”与“工程” 8 1.2.8 使用命令行工具编译 8 第2章 Windows API概要 10 2.1 Windows数据类型 10 2.1.1 Windows数据类型示例 10 2.1.2 Windows数据类型与标准C数据类型的关系 14 2.1.3 Windows数据类型与Windows API 14 2.1.4 Windows中的数据结构 15 2.2 Windows API的功能分类 15 2.2.1 系统基本服务 15 2.2.2 系统管理 17 2.2.3 用户界面 17 2.2.4 图像和多媒体 20 2.2.5 网络 20 2.2.6 系统安全 20 2.2.7 其他功能 21 2.3 Windows API核心DLL 21 2.3.1 Kernel32.dll 21 2.3.2 User32.dll 21 2.3.3 Gdi32.dll 22 2.3.4 标准C函数 22 2.3.5 其他Dll 22 2.4 Unicode和多字节 22 2.4.1 W版本和A版本的API 24 2.4.2 Unicode与ASCII的转换 24 2.5 对Windows程序设计规范的建议 25 第3章 开发工具配置与使用 26 3.1 使用Visual C/C++编译链接工具 26 3.1.1 编译器cl.exe 27 3.1.2 资源编译器rc.exe 31 3.1.3 链接器link.exe 32 3.1.4 其他工具 38 3.1.5 编译链接工具依赖的环境变量 39 3.1.6 示例:使用/D选项进行条件编译 42 3.2 使用Platform SDK 43 3.2.1 Platform SDK的目录结构与功能 43 3.2.2 为编译链接工具设置环境变量 45 3.2.3 Platform SDK工具集 46 3.2.4 Windows Vista SDK 48 3.3 编写Makefile 48 3.3.1 使用nmake.exe构建工程 48 3.3.2 Makefile实例 50 3.3.3 注释 50 3.3.4 宏 50 3.3.5 描述块:目标、依赖项和命令 53 3.3.6 makefile预处理 55 3.3.7 在Platform SDK的基础上使用nmake 56 3.4 使用WinDbg调试 57 3.4.1 安装WinDbg 57 3.4.2 编译可调试的程序 58 3.4.3 WinDbg命令 59 3.4.4 调试过程演示 59 3.5 集成开发环境 Visual Studio 62 3.5.1 工程类型选择与配置 62 3.5.2 Visual Studio快捷方式 64 3.5.3 生成项目 64 3.5.4 调试 65 3.5.5 选项与设置 65 3.6 开发环境配置总结 66 第4章 文件系统 67 4.1 概述 67 4.1.1 文件系统的基本概念 67 4.1.2 文件系统主要API 68 4.2 磁盘和驱动器管理 70 4.2.1 遍历卷并获取属性 70 4.2.2 操作驱动器挂载点 76 4.2.3 判断光驱中是否有光盘 81 4.2.4 获取磁盘分区的总容量、空闲容量、簇、扇区信息 83 4.3 文件和目录管理 86 4.3.1 删除、复制、重命名、移动文件 87 4.3.2 创建、打开、读写文件,获取文件大小 90 4.3.3 创建目录 96 4.3.4 获取程序所在的目录、程序模块路径,获取和设置当前目录 97 4.3.5 查找文件、遍历指定目录下的文件和子目录 100 4.3.6 递归遍历目录树 103 4.3.7 获取、设置文件属性和时间 105 4.4 内存映射文件 110 4.4.1 使用Mapping File提高文件读写的效率 110 4.4.2 通过Mapping File在进程间传递和共享数据 115 4.4.3 通过文件句柄获得文件路径 118 4.5 总结 121 第5章 内存管理 122 5.1 Windows内存管理原理 122 5.1.1 基本概念 122 5.1.2 分页与分段内存管理、内存映射与地址转换 123 5.1.3 进程的内存空间 125 5.1.4 虚拟内存布局、内存的分工、堆与栈 127 5.1.5 内存的保护属性和存取权限 127 5.1.6 本章API列表 127 5.2 堆管理 129 5.2.1 获取堆句柄、分配与再分配堆 129 5.2.2 获取堆中内存块的大小信息 133 5.2.3 释放内存、销毁堆 134 5.3 全局(Global)和局部(Local)内存管理 136 5.3.1 Global函数 136 5.3.2 Local函数 137 5.3.3 使用全局和局部函数分配和释放内存、改变内存块属性 137 5.4 虚拟内存管理 138 5.4.1 虚拟地址空间与内存分页 139 5.4.2 分配和释放可读可写的虚拟内存页面 139 5.4.3 修改内存页面状态和保护属性、将页面锁定在物理内存中 142 5.4.4 管理其他进程的虚拟内存 143 5.5 内存操作与内存信息管理 144 5.5.1 复制、填充、移动、清零内存块、防止缓冲区溢出 144 5.5.2 获得当前系统内存使用情况 146 5.5.3 判断内存指针的可用性 147 5.6 各种内存分配方式的关系与比较 148 5.6.1 标准C内存管理函数与Windows内存管理API的关系 149 5.6.2 功能性区别 149 5.6.3 效率的区别 149 第6章 进程、线程和模块 150 6.1 基本概念 150 6.1.1 应用程序与进程 150 6.1.2 控制台应用程序与图形用户界面应用程序 151 6.1.3 动态链接库、模块 151 6.1.4 线程、纤程与作业 152 6.1.5 权限与优先级 153 6.2 进程管理 153 6.2.1 创建进程、获取进程相关信息、获取启动参数 153 6.2.2 编写控制台程序和图形用户界面应用程序 158 6.2.3 获取和设置环境变量 158 6.3 线程、纤程 162 6.3.1 创建线程、退出线程、获取线程信息 162 6.3.2 挂起、恢复、切换、终止线程 164 6.3.3 创建远程线程、将代码注入其他进程中执行 167 6.3.4 创建纤程、删除纤程、调度纤程 170 6.3.5 纤程与线程的互相转换 171 6.4 进程状态信息 176 6.4.1 PS API与Tool help API 176 6.4.2 遍历系统中的进程 178 6.4.3 列举进程的模块、线程 182 6.4.4 进程的堆使用、内存占用、虚拟内存大小,页面错误情况 184 6.5 动态链接库 185 6.5.1 加载、释放DLL、通过句柄获取DLL相关信息 186 6.5.2 编写动态链接库、导出函数 186 6.5.3 创建动态链接库工程,配置DLL编译链接选项 188 6.5.4 运行时动态获取DLL导出函数地址并调用 189 6.5.5 声明导出函数、创建lib库,为其他模块提供导入表调用接口 190 6.5.6 通过构建导入表调用DLL导出函数 191 第7章 线程同步 192 7.1 基本原理 192 7.1.1 线程同步的过程 193 7.1.2 同步对象 193 7.1.3 等待函数 193 7.2 同步对象示例 194 7.2.1 使用事件对象(Event) 194 7.2.2 使用互斥对象(Mutex) 199 7.2.3 使用信号量控制访问共享数据的线程数量 202 7.2.4 使用可等待计时器(Timer) 206 7.3 等待进程和线程的执行完成 209 第8章 服务 210 8.1 基本概念 210 8.1.1 服务控制器(SCM) 211 8.1.2 服务程序 211 8.1.3 服务控制管理程序 211 8.1.4 系统服务管理工具 211 8.1.5 服务的属性 211 8.2 编写服务程序 212 8.2.1 入口函数 212 8.2.2 服务主函数 212 8.2.3 控制处理函数 213 8.3 实现对服务的控制和管理 216 8.3.1 创建、删除服务 216 8.3.2 启动、停止服务,向服务发送控制请求 219 8.3.3 管理服务状态、配置服务、服务的依赖关系 222 第9章 图形用户界面 229 9.1 字符界面程序 229 9.1.1 基本概念 230 9.1.2 控制台读写 231 9.1.3 控制台字体、颜色等属性,操作屏幕缓存 234 9.1.4 控制台事件 244 9.2 图形用户界面:基本概念 246 9.2.1 窗口 246 9.2.2 窗口类 246 9.2.3 消息和消息处理函数 247 9.2.4 控件 247 9.2.5 资源 248 9.2.6 对话框 248 9.3 图形用户界面:窗口 248 9.3.1 注册窗口类 249 9.3.2 创建窗口 251 9.3.3 窗口消息处理函数 253 9.3.4 窗口属性、位置和大小 256 9.3.5 窗口显示方式 257 9.3.6 线程消息队列和消息循环 258 9.4 图形用户界面:控件 258 9.4.1 Tree View控件 258 9.4.2 为Tree View控件增加节点 260 9.4.3 Tree View右键菜单 262 9.4.4 List View控件 263 9.4.5 为List View控件增加分栏 265 9.4.6 为List View控件增加项 266 9.4.7 文本框控件 267 9.4.8 为文本框控件设置文字 268 9.5 界面资源 269 9.5.1 资源脚本(.rc) 269 9.5.2 资源ID定义和头文件 272 9.5.3 在程序中使用资源 273 9.6 菜单 273 9.6.1 菜单资源和菜单句柄 273 9.6.2 动态增加、删除、设置菜单及菜单项 274 9.6.3 菜单消息处理 274 9.7 对话框 275 9.7.1 创建对话框 275 9.7.2 对话框消息处理函数 276 第10章 系统信息的管理 277 10.1 Windows系统信息 277 10.1.1 获取系统版本 277 10.1.2 获取计算机硬件信息 279 10.1.3 获取系统目录等信息 281 10.1.4 用户名、计算机名、域名 282 10.1.5 处理系统颜色信息、尺度信息等 284 10.1.6 鼠标、键盘等外设信息 285 10.2 时间信息 286 10.2.1 设置、获取系统时间 286 10.2.2 获取开机至现在持续的时间 287 10.2.3 文件时间与系统时间的转换 287 10.3 注册表 288 10.3.1 注册表的作用及组织形式 288 10.3.2 键、子键、键属性及键值的相关操作 289 10.3.3 列举注册表项及键值 292 10.3.4 通过注册表设置一个自启动的程序 293 10.3.5 设置随程序启动而启动的调试器(任何程序) 294 10.3.6 指定程序崩溃实时调试器 294 第11章 进程间通信 295 11.1 邮槽(MailSlot) 295 11.1.1 创建邮槽、从邮槽中读取消息 296 11.1.2 通过邮槽发送消息 299 11.2 管道(Pipe) 300 11.2.1 创建命名管道 300 11.2.2 管道监听 302 11.2.3 使用异步I/O进行读写 303 11.2.4 关闭管道实例 307 11.2.5 客户端 307 11.3 剪贴板 310 11.3.1 获取、设置剪贴板数据 310 11.3.2 监视剪贴板 317 11.3.3 剪贴板数据格式 325 11.4 数据复制消息(WM_COPYDATA) 327 11.4.1 数据发送端 327 11.4.2 数据接收端 330 11.5 其他进程间通信方式 332 11.5.1 动态数据交换(DDE)和网络动态数据交换(NDDE) 332 11.5.2 通过File Mapping在进程间共享数据 333 11.5.3 Windows Socket 333 第12章 Windows Shell程序设计 334 12.1 Windows Shell目录管理 335 12.1.1 Shell对目录和文件的管理形式 335 12.1.2 “我的文档”等特殊目录相关操作 335 12.1.3 绑定、遍历、属性获取 337 12.1.4 浏览文件对话框 339 12.2 文件协助(File Associations) 340 12.2.1 文件类型相关注册表键值 340 12.2.2 为文件指定默认打开程序 341 12.2.3 定制文件类型的图标 342 12.3 Shell扩展 343 12.3.1 对象及概念 343 12.3.2 CLSID,处理例程的GUID 344 12.3.3 注册Shell扩展 345 12.3.4 COM程序开发基础 346 12.3.5 编写Handler程序 346 12.3.6 Shell扩展程序的调试 362 12.3.7 总结 363 12.4 任务栏通知区域(Tray)图标 363 12.4.1 创建图标窗口 364 12.4.2 创建图标和图标菜单 367 12.4.3 最小化主窗口到通知区域 370 12.4.4 弹出气泡通知 372 12.4.5 动态图标 374 12.4.6 其他功能 376 第13章 Windows GDI 379 13.1 GDI编程接口概述 379 13.1.1 Windows GDI的功能 379 13.1.2 链接库与头文件 380 13.2 设备上下文(DC)、输出操作与图形对象 380 13.2.1 设备上下文类型与关联设备 380 13.2.2 图形对象的作用及与DC的关系 380 13.2.3 各类图形对象的具体属性与作用 383 13.2.4 绘制、填充、写入等图形输出操作 384 13.2.5 修剪与坐标变换 385 13.2.6 设备上下文的图形模式 385 13.3 一个最简单的GDI程序 386 13.3.1 示例 386 13.3.2 DC的操作 387 13.3.3 颜色的表示 388 13.3.4 图形对象:画刷和画笔 389 13.3.5 输出操作:绘制图形和线条 390 13.4 文字和字体 391 13.4.1 选择、设置字体 393 13.4.2 选择字体图形对象 394 13.4.3 文字的颜色 394 13.4.4 输出文字 395 13.4.5 DC图形模式设置 395 13.4.6 遍历字体 396 13.4.7 为系统安装、删除字体文件 398 13.5 绘制线条 398 13.5.1 选择画笔对象 399 13.5.2 直线 399 13.5.3 绘制任意曲线 399 13.5.4 跟踪鼠标轨迹 399 13.5.5 弧线 405 13.6 绘制图形 405 13.6.1 填充颜色与边缘勾勒 406 13.6.2 绘制矩形、椭圆、圆角矩形 406 13.6.3 椭圆弓形和椭圆扇形 411 13.6.4 多边形 411 13.6.5 RECT结构及对RECT的操作 412 13.7 位图操作 414 13.7.1 截取屏幕、保存位图文件 414 13.7.2 将位图显示在界面上 419 13.8 区域(Regions)、路径(Paths)与修剪(Clip)操作 422 13.8.1 区域的创建及形状、位置等属性 422 13.8.2 区域边沿、区域填充、反转与勾勒操作 423 13.8.3 组合、比较、移动等操作 426 13.8.4 点击测试(Hit Testing) 427 13.8.5 路径的创建与操作 431 13.8.6 路径转换为区域 432 13.8.7 使用区域和路径进行修剪操作,限制输出 432 13.9 坐标变换 438 13.9.1 缩放 439 13.9.2 旋转 440 13.10 调色板 440 第14章 网络通信与配置 443 14.1 Socket通信 444 14.1.1 客户端 444 14.1.2 服务端 449 14.1.3 处理并发的客户端连接 455 14.1.4 网络通信的异步I/O模式 456 14.2 IP Helper 456 第15章 程序安装与设置 463 15.1 创建cab文件 463 15.1.1 makecab.exe 463 15.1.2 压缩多个文件 464 15.1.3 Cabinet软件开发工具包(CABSDK) 466 15.2 编写INF文件 466 15.2.1 INF文件格式 466 15.2.2 Install节 468 15.2.3 CopyFiles和AddReg等安装过程 468 15.2.4 源路径和目的路径 469 15.2.5 字符串表 469 15.3 安装程序setup.exe的编号 469 15.4 使用msi文件进行安装 472 15.4.1 Windows Installer Service 472 15.4.2 msi文件的创建与修改工具orca.exe 474 15.4.3 准备工作 475 15.4.4 编辑表组 475 第16章 设备驱动管理与内核通信 476 16.1 设备管理 476 16.1.1 列举设备接口 477 16.1.2 监控设备的加载和卸载 483 16.2 I/O控制、内核通信 488 16.2.1 加载驱动程序 488 16.2.2 控制驱动程序、与驱动程序进行通信 495 16.3 编写设备驱动程序 498 16.3.1 驱动程序开发包:DDK 499 16.3.2 开发驱动程序 499 16.4 I/O模式,同步与异步 504 第17章 用户、认证和对象安全 506 17.1 基本概念 506 17.1.1 访问令牌、权限和用户标识 506 17.1.2 进程的系统操作权限 507 17.1.3 安全对象 508 17.1.4 访问控制列表(ACL) 508 17.2 安全机制程序示例 509 17.2.1 列举进程访问令牌内容和权限 509 17.2.2 修改进程的权限 514 17.2.3 列举安全对象的安全描述符 515 17.2.4 修改安全描述符 521 17.3 用户 522 17.3.1 创建用户 522 17.3.2 用户组 523 17.3.3 删除用户 525 17.3.4 列举用户用户组、获取用户信息 525 第18章 Windows API的内部原理 532 18.1 关于API的补充说明 532 18.1.1 Windows API的版本演进和Vista新增API 532 18.1.2 64位操作系统的接口 533 18.2 Windows系统中的对象封装 533 18.2.1 什么是对象 534 18.2.2 面向对象的思想 534 18.2.3 Windows系统中的对象:内核对象、GDI对象等 534 18.3 Windows程序设计参考:文档资源与样例代码 534 18.3.1 SDK文档和MSDN 534 18.3.2 SDK示例代码 535 18.4 x86平台程序函数调用原理 535 18.4.1 函数调用的真实过程 535 18.4.2 函数调用约定 539 18.4.3 为什么通过参数返回数据时只能使用指针 540 18.4.4 缓冲区溢出 540 18.4.5 程序运行错误的调试技巧 540 18.5 可执行程序结构与API函数接口内部机理 541 18.5.1 Windows可执行程序结构 541 18.5.2 导入表、导出表、动态链接 543 18.5.3 NTDLL.DLL、NATIVE API和SSDT 544 18.5.4 API HOOK 546 18.6 发布程序 546 18.6.1 合理选择编译链接选项 546 18.6.2 构建到指定路径 546 18.7 模块化,向Windows API学习接口定义 547 18.7.1 lib文件 547 18.7.2 头文件 547 18.7.3 为第三方应用软件提供SDK 547
数字图像处理方面的经典教材,中文译本 阮秋琦,阮宇智等译 本书是把图像处理基础理论论述与软件实践方法相结合的第一本书,它集成了冈萨雷斯和伍兹所著的《数字图像处理》一书中的重要内容和MathWorks公司的图像处理工具箱。本书的特色在于它重点强调了怎样通过开发新代码来增强这些软件工具。本书在介绍MATLAB编程基础知识之后,讲述了图像处理的主要内容,具体包括亮度变换、线性和非线性空间滤波、频率域滤波、图像复原与配准、彩色图像处理、小波、图像数据压缩、形态学图像处理、图像分割、区域和边界表示与描述以及对象识别等。 本书概念清晰,层次分明,可供从事信号与信息处理、计算机科学与技术、通信工程、地球物理、医学等专业的大专院校师生学习参考,也可供相应的工程技术人员参考使用。 本书概念清晰,层次分明,可供从事信号与信息处理、计算机科学与技术、通信工程、地球物理、医学等专业的大专院校师生学习参考,也可供相应的工程技术人员参考使用。 第1章 绪言  前言  1.1 背景知识  1.2 什么是数字图像处理  1.3 MATLAB和图像处理工具箱的背景知识  1.4 本书涵盖的图像处理范围  1.5 本书的Web站点  1.6 MATLAB工作环境   1.6.1 MATLAB桌面   1.6.2 使用MATLAB编辑器创建M文件   1.6.3 获得帮助   1.6.4 保存和检索工作会话  1.7 参考文献的组织方式  小结 第2章 基本原理  前言  2.1 数字图像的表示   2.1.1 坐标约定   2.1.2 图像的矩阵表示  2.2 读取图像  2.3 显示图像  2.4 保存图像  2.5 数据类  2.6 图像类型   2.6.1 亮度图像   2.6.2 二值图像   2.6.3 术语注释  2.7 数据类与图像类型间的转换   2.7.1 数据类间的转换   2.7.2 图像类和类型间的转换  2.8 数组索引   2.8.1 向量索引   2.8.2 矩阵索引   2.8.3 选择数组的维数  2.9 一些重要的标准数组  2.10 M函数编程简介   2.10.1 M文件   2.10.2 运算符   2.10.3 流控制   2.10.4 代码优化   2.10.5 交互式I/O   2.10.6 单元数组与结构简介  小结 第3章 亮度变换与空间滤波  前言  3.1 背景知识  3.2 亮度变换函数   3.2.1 函数imadjust   3.2.2 对数和对比度拉伸变换   3.2.3 亮度变换的一些实用M函数  3.3 直方图处理与函数绘图   3.3.1 生成并绘制图像的直方图   3.3.2 直方图均衡化   3.3.3 直方图匹配(规定化)  3.4 空间滤波   3.4.1 线性空间滤波   3.4.2 非线性空间滤波  3.5 图像处理工具箱的标准空间滤波器   3.5.1 线性空间滤波器   3.5.2 非线性空间滤波器  小结 第4章 频域处理  前言  4.1 二维离散傅里叶变换  4.2 在MATLAB中计算并可视化二维DFT  4.3 频域滤波   4.3.1 基本概念   4.3.2 DFT滤波的基本步骤   4.3.3 用于频域滤波的M函数  4.4 从空间滤波器获得频域滤波器  4.5 在频域中直接生成滤波器   4.5.1 建立用于实现频域滤波器的网格数组   4.5.2 低通频域滤波器   4.5.3 线框图与表面图  4.6 锐化频域滤波器   4.6.1 基本的高通滤波器   4.6.2 高频强调滤波  小结 第5章 图像复原  前言  5.1 图像退化/复原处理的模型  5.2 噪声模型   5.2.1 使用函数imnoise添加噪声   5.2.2 使用指定的分布产生空间随机噪声   5.2.3 周期噪声   5.2.4 估计噪声参数  5.3 仅有噪声的复原:空间滤波   5.3.1 空间噪声滤波器   5.3.2 自适应空间滤波器  5.4 通过频域滤波来降低周期噪声  5.5 退化函数建模  5.6 直接逆滤波  5.7 维纳滤波  5.8 约束的最小二乘方(正则)滤波  5.9 使用Lucy-Richardson算法的迭代非线性复原  5.10 盲去卷积  5.11 几何变换与图像配准   5.11.1 空间几何变换   5.11.2 对图像应用空间变换   5.11.3 图像配准  小结 第6章 彩色图像处理  前言  6.1 MATLAB中彩色图像的表示方法   6.1.1 RGB图像   6.1.2 索引图像   6.1.3 用来处理RGB图像和索引图像的IPT函数  6.2 转换至其他彩色空间   6.2.1 NTSC彩色空间   6.2.2 YCb
比较适合第1 部分 OPNET Modeler 简介 第1 章 OPNET 仿真概述...........................................................................................6 1.1 网络仿真简介 1.2 OPNET 简介 1.3 OPNET 网络环境 1.4 OPNET 编辑器简介 1.5 配置一个简单的网络 1.5.1 定义问题...........................................................................................28 1.5.2 建立网络拓扑结构...........................................................................28 1.5.3 收集统计量.......................................................................................36 1.5.4 保存项目...........................................................................................38 1.5.5 运行仿真...........................................................................................38 1.5.6 查看结果...........................................................................................39 1.5.7 复制场景并扩展网络.......................................................................40 1.5.8 再次运行...........................................................................................42 1.5.9 比较结果...........................................................................................42 第2 章 OPNET Modeler 环境变量的设置及文件管理...........................................45 2.1 OPNET Modeler 环境变量的设置..............................................................45 2.1.1 Windows 2000 下环境变量的设置..................................................45 2.1.2 Unix 下环境变量的设置..................................................................45 2.2 OPNET 常用文件格式................................................................................24 OPNET 网络仿真 – 陈敏 4 2.3 OPNET 文件管理 第2 部分 OPNET Modeler 使用(基本篇) 第3 章 OPNET 的通信仿真机制.............................................................................48 3.1 离散事件仿真机制......................................................................................48 3.1.1 OPNET 中的事件推进机制.............................................................48 3.1.2 同一时刻事件优先级的界定...........................................................49 3.2 基于包的通信..............................................................................................50 3.3 使用接口控制信息进行通信......................................................................53 3.4 点对点和总线管道阶段 第5 章 收集、查看、导出以及发布仿真结果................................................................. 115 5.1 收集统计量................................................................................................ 115 5.1.1 收集矢量统计量............................................................................. 115 5.1.2 收集标量统计量............................................................................. 116 5.2 查看和导出仿真结果................................................................................ 116 5.3 发布仿真结果 第6 章 OPNET Modeler 编程基础........................................................................ 118 6.1 从例程开始——创建一个包交换网络.................................................... 118 6.1.1 概述................................................................................................. 118 6.1.2 开始建立......................................................................................... 118 6.1.3 创建新的包格式.............................................................................120 6.1.4 创建新的链路模型.........................................................................121 6.1.5 创建中心交换节点模型................................................................. 123 6.1.6 创建hub 进程模型.........................................................................126 6.1.7 创建周边节点模型.........................................................................128 6.1.8 创建网络模型.................................................................................135 6.1.9 收集统计量并分析结果................................................................. 137 6.1.10 配置仿真.......................................................................................138 6.1.11 运行仿真.......................................................................................140 6.2 OPNET Modeler 核心函数介绍............................................................... 143 6.2.1 动画类核心函数.............................................................................143 6.2.2 分布类核心函数.............................................................................149 6.2.3 事件类核心函数.............................................................................150 6.2.4 接口控制类核心函数..................................................................... 152 6.2.5 标识类核心函数.............................................................................152 第1 章 OPNET 仿真概述 5 6.2.6 内部模型访问类核心函数............................................................. 153 6.2.7 中断类核心函数.............................................................................154 6.2.8 包类核心函数.................................................................................155 6.2.9 进程类核心函数.............................................................................157 6.2.10 队列类核心函数...........................................................................158 6.2.11 分割与组装类核心函数............................................................... 159 6.2.12 统计类核心函数...........................................................................162 6.2.13 队列和子队列类核心函数........................................................... 163 6.2.14 表格类核心函数...........................................................................165 6.2.15 传输类核心函数...........................................................................165 6.2.16 拓扑结构类核心函数................................................................... 165 6.2.17 编程类核心函数...........................................................................166 6.3 子 进 程..............................................................................................168 6.3.1 有关进程的几个概念..................................................................... 169 6.3.2 子进程的初始化.............................................................................170 6.3.3 仿真核心使用权的管理模式......................................................... 170 6.3.4 进程对仿真核心控制权获取方式的识别..................................... 172 6.3.5 进程间的内存共享机制................................................................. 173 6.3.6 使用子进程可能出现的几种错误 第3 部分 OPNET Modeler 使用(高级篇) 186 第7 章 OPNET 的调试...........................................................................................175 7.1 查看OPNET 日志文件 7.2 使用OPNET Debugger 调试............................................................. 175 7.2.1 ODB 调试概述................................................................................175 7.2.2 针对结构错误(Structural Error)的ODB 调试实例 7.2.3 针对逻辑错误的ODB 调试实例 7.2.4 针对进程模块的ODB 调试........................................................... 176 7.2.5 调整ODB 窗口缓存大小................................................................. 181 7.3 OPNET 与Visual C++联合调试....................................................... 183 7.3.1 VC 的安装及环境变量的设置....................................................... 183 7.3.2 修改OPNET 有关与VC 联合调试的属性................................... 184 7.3.3 仿真时OPNET 与VC 联合调试的步骤....................................... 185 7.4 常见错误及其说明 第8 章 业务建模 8.1 ON/OFF 业务建模 8.2 配置标准端对端业务 OPNET 网络仿真 – 陈敏 6 8.2.1 设定应用参数 8.2.2 设定业务主询 8.2.3 配置服务器支持的应用 8.2.4 设定客户端业务主询 8.3 自定义多端业务 8.4 流业务建模技巧 8.4.1 针对话音和视频业务背景流的设置 8.4.2 应用流背景流建模 8.4.3 网络层背景流建模 8.4.4 Micro-Simulation 技术 8.5 链路背景业务建模 8.6 混合业务建模 第9 章 无线信道建模.............................................................................................186 9.1 无线模拟简介 9.2 无线移动方式 9.2.1 分段移动方式 9.2.2 设置向量轨迹的方式 9.2.3 修改节点的位置属性 9.2.4 使用移动配置器(Mobility Config) 9.3 无线收发机管道建模................................................................................205 9.3.1 接收主询.........................................................................................205 9.3.2 传输时延.........................................................................................206 9.3.3 物理可达性.....................................................................................206 9.3.4 信道匹配.........................................................................................206 9.3.5 发射机天线增益.............................................................................207 9.3.6 传播延时.........................................................................................208 9.3.7 收信机天线增益.............................................................................208 9.3.8 接收功率.........................................................................................209 9.3.9 干扰噪声功率.................................................................................210 9.3.10 背景噪声功率...............................................................................210 9.3.11 信噪比........................................................................................... 211 9.3.12 误比特率.......................................................................................212 9.3.13 错误分布.......................................................................................212 9.3.14 错误纠正.......................................................................................212 9.4 加快无线仿真的速度 9.4.1 采用优化的仿真核心 9.4.2 在仿真中动态删减接收主询成员 第1 章 OPNET 仿真概述 7 9.4.3 简化无线封包的复制 9.4.4 动态更新接收主询 9.4.5 通过无线区域划分接收主询 9.4.6 过滤无关的管道阶段 9.4.7 采用并行仿真 9.5 创建一个移动无线网络..............................................................................187 9.2.1 概述.................................................................................................187 9.2.2 开始建立.........................................................................................187 9.2.3 创建天线模型.................................................................................188 9.2.4 创建指向处理器.............................................................................192 9.2.5 创建节点模型.................................................................................193 9.2.6 创建网络模型.................................................................................197 9.2.7 收集统计量并运行仿真................................................................. 199 9.2.8 查看并分析结果.............................................................................202 第10 章 OPNET 标准模块介绍.............................................................................215 10.1 IEEE 802.11 模块内部结构及仿真......................................................... 215 10.1.1 IEEE 802.11 无线局域网概述...................................................... 215 10.1.2 无线局域网的协议行为建模....................................................... 215 10.1.3 IEEE 802.11 无线局域网MAC 的输入接口.............................. 218 10.1.4 IEEE 802.11 无线局域网MAC 的输出接口.............................. 220 10.1.5 仿真和实验...................................................................................221 10.2 X.25 模块介绍.........................................................................................224 10.2.1 引言...............................................................................................224 10.2.2 基于X.25 传输控制协议的应用会话建立流程......................... 225 10.2.3 基于X.25 数据链路的建立和包交换流程................................. 226 10.3 干扰机模型..............................................................................................227 10.4 OPNET IPv6 模块介绍及仿真................................................................ 257 13.1 ICMPv6 Route Print 场景............................................................... 257 13.2 Manual Tunnel .................................................................................268 10.5 小区系统模型 10.5.1 模型的导入 10.5.2 模型的适用范围和限制 10.5.3 模型包含的文件 10.5.4 模型的属性 10.5.5 模型的接口 OPNET 网络仿真 – 陈敏 8 第4 部分 OPNET Modeler 的高级应用 186 第11 章 自定义动画编程的运用...........................................................................244 11.1 动态队列计量器..............................................................................244 11.1.1 设置探针属性 11.1.2 动态队列计量器动画程序讲解 11.2 无线包传输......................................................................................245 11.2.1 设置探针属性 11.2.2 无线包传输动画初始化程序 11.2.3 在接收功率阶段加入动画程序 11.2.4 在干扰噪声功率计算阶段加入动画程序 11.2.5 在错误纠正阶段加入动画程序 第12 章 自定义流媒体协议的实现....................................................................... 231 12.1 OPNET 应用层建模构架................................................................ 231 12.2 自定义的应用协议..........................................................................232 12.3 修改头文件“gna_mgr.h” ............................................................... 236 12.4 在应用配置进程模型中增加应用属性.......................................... 237 第13 章 自定义IP 协议的实现 13.1 自定义IP 协议接口 13.2 IP 包的创建和高层数据包的封装 13.3 IP 路由表初始化 13.4 路由表的查找 第14 章 图形化建模和文本方式建模EMA......................................................... 229 14.1 EMA 配置网络模型........................................................................ 229 14.2 EMA 与外部数据的接口 14.2.1 EMA 设置对象的固有属性 14.2.2 EMA 设置对象的自定义属性 第15 章 高级体系架构(HLA) ................................................................................ 254 15.1 RTI 的安装及其环境变量设置 15.2 建立控制联邦成员 15.3 OPNET HLA 仿真实例 15.3.1 准备所需的文件 15.3.2 运行HLA 仿真环境 15.3.3 实现HLA 交互 15.3.4 多个OPNET 联邦成员联机仿真 附录A 本书中英文术语对照表 271 附录B 参考文献 271 第1 章 OPNET 仿真概述 9 附录C 关于本书存在的问题
The C++ Standard Library A Tutorial and Reference (2nd Edition)+cppstdlib-code.zip C++标准库(第二版)英文版.pdf 非扫描版+源代码 Prefaceto the SecondEdition xxiii Acknowledgments for the SecondEdition xxiv Prefaceto the FirstEdition xxv Acknowledgments for the FirstEdition xxvi 1 About This Book 1 1.1 Why This Book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Before ReadingThis Book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.3 Styleand Structure of the Book . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.4 How to ReadThis Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.5 Stateof the Art . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.6 Example Codeand AdditionalInformation . . . . . . . . . . . . . . . . . . . . . 5 1.7 Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2 Introduction to C++ and the StandardLibrary 7 2.1 Historyof the C++ Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1.1 Common Questionsabout the C++11 Standard . . . . . . . . . . . . . . 8 2.1.2 Compatibility between C++98 and C++11 . . . . . . . . . . . . . . . . . 9 2.2 Complexity and Big-O Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3 New LanguageFeatures 13 3.1 New C++11 Language Features . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.1.1 Important MinorSyntax Cleanups . . . . . . . . . . . . . . . . . . . . . 13 3.1.2 AutomaticType Deductionwith auto . . . . . . . . . . . . . . . . . . . 14 3.1.3 UniformInitialization and Initializer Lists . . . . . . . . . . . . . . . . . 15 3.1.4 Range-Basedfor Loops . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.1.5 MoveSemanticsand Rvalue References . . . . . . . . . . . . . . . . . . 19 viii Contents 3.1.6 New String Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.1.7 Keyword noexcept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.1.8 Keyword constexpr . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.1.9 New Template Features . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.1.10 Lambdas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.1.11 Keyword decltype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.1.12 New Function Declaration Syntax . . . . . . . . . . . . . . . . . . . . . 32 3.1.13 Scoped Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.1.14 New FundamentalData Types . . . . . . . . . . . . . . . . . . . . . . . 33 3.2 Old “New” Language Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.2.1 ExplicitInitialization for FundamentalTypes . . . . . . . . . . . . . . . 37 3.2.2 Definitionof main() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 4 GeneralConcepts 39 4.1 Namespace std . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 4.2 Header Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 4.3 Errorand ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.3.1 Standard ExceptionClasses. . . . . . . . . . . . . . . . . . . . . . . . . 41 4.3.2 Members of ExceptionClasses. . . . . . . . . . . . . . . . . . . . . . . 44 4.3.3 PassingExceptions with Classexception_ptr . . . . . . . . . . . . . . 52 4.3.4 Throwing Standard Exceptions . . . . . . . . . . . . . . . . . . . . . . . 53 4.3.5 Deriving from Standard ExceptionClasses. . . . . . . . . . . . . . . . . 54 4.4 CallableObjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 4.5 Concurrencyand Multithreading. . . . . . . . . . . . . . . . . . . . . . . . . . . 55 4.6 Allocators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 5 Utilities 59 5.1 Pairs and Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 5.1.1 Pairs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 5.1.2 Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 5.1.3 I/O for Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 5.1.4 Conversions between tuple sandpairs . . . . . . . . . . . . . . . . . . 75 5.2 Smart Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 5.2.1 Classshared_ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 5.2.2 Classweak_ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 5.2.3 Misusing Shared Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . 89 5.2.4 Shared and WeakPointersin Detail. . . . . . . . . . . . . . . . . . . . . 92 5.2.5 Classunique_ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Contents ix 5.2.6 Classunique_ptrin Detail . . . . . . . . . . . . . . . . . . . . . . . . 110 5.2.7 Classauto_ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 5.2.8 FinalWordsonSmart Pointers . . . . . . . . . . . . . . . . . . . . . . . 114 5.3 Numeric Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 5.4 Type Traitsand Type Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 5.4.1 Purposeof Type Traits . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 5.4.2 Type Traitsin Detail. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 5.4.3 ReferenceWrappers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 5.4.4 Function Type Wrappers . . . . . . . . . . . . . . . . . . . . . . . . . . 133 5.5 Auxiliary Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 5.5.1 Processing the Minimumand Maximum. . . . . . . . . . . . . . . . . . 134 5.5.2 Swapping Two Va l u e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 5.5.3 SupplementaryComparison Operators . . . . . . . . . . . . . . . . . . . 138 5.6 Compile-Time FractionalArithmeticwith Classratio . . . . . . . . . . . . . 140 5.7 Clocks and Timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 5.7.1 Overview of the ChronoLibrary . . . . . . . . . . . . . . . . . . . . . . 143 5.7.2 Durations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 5.7.3 Clocks and Timepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 5.7.4 Date and TimeFunctions byC and POSIX . . . . . . . . . . . . . . . . . 157 5.7.5 Blocking with Timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 5.8 Header Files , ,and . . . . . . . . . . . . . . 161 5.8.1 Definitionsin . . . . . . . . . . . . . . . . . . . . . . . . . . 161 5.8.2 Definitionsin . . . . . . . . . . . . . . . . . . . . . . . . . . 162 5.8.3 Definitionsin . . . . . . . . . . . . . . . . . . . . . . . . . . 163 6 The StandardTe m p l a t e Library 165 6.1 STL Components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 6.2 Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 6.2.1 Sequence Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 6.2.2 Associative Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 6.2.3 UnorderedContainers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 6.2.4 Associative Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 6.2.5 OtherContainers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 6.2.6 Container Adapters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 6.3 Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 6.3.1 Further Examples of UsingAssociative and UnorderedContainers . . . . 193 6.3.2 Iterator Categories. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 x Contents 6.4 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 6.4.1 Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 6.4.2 Handling MultipleRanges . . . . . . . . . . . . . . . . . . . . . . . . . 207 6.5 Iterator Adapters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 6.5.1 Insert Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 6.5.2 Stream Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 6.5.3 ReverseIterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 6.5.4 MoveIterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 6.6 User-DefinedGenericFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 6.7 ManipulatingAlgorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 6.7.1 “Removing”Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 6.7.2 ManipulatingAssociative and UnorderedContainers . . . . . . . . . . . 221 6.7.3 Algorithms versus MemberFunctions . . . . . . . . . . . . . . . . . . . 223 6.8 Functions as AlgorithmArguments . . . . . . . . . . . . . . . . . . . . . . . . . 224 6.8.1 UsingFunctions as AlgorithmArguments . . . . . . . . . . . . . . . . . 224 6.8.2 Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 6.9 UsingLambdas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 6.10 Function Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 6.10.1 Definitionof Function Objects . . . . . . . . . . . . . . . . . . . . . . . 233 6.10.2 PredefinedFunction Objects . . . . . . . . . . . . . . . . . . . . . . . . 239 6.10.3 Binders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 6.10.4 Function Objectsand Bindersversus Lambdas . . . . . . . . . . . . . . . 243 6.11 Container Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 6.11.1 Requirements for Container Elements . . . . . . . . . . . . . . . . . . . 244 6.11.2 Va l u eSemanticsor ReferenceSemantics. . . . . . . . . . . . . . . . . . 245 6.12 Errors and Exceptions inside the STL . . . . . . . . . . . . . . . . . . . . . . . . 245 6.12.1 ErrorHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 6.12.2 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 6.13 Extendingthe STL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 6.13.1 Integrating AdditionalTypes . . . . . . . . . . . . . . . . . . . . . . . . 250 6.13.2 Deriving from STL Types . . . . . . . . . . . . . . . . . . . . . . . . . . 251 7 STL Containers 253 7.1 Common Container Abilitiesand Operations . . . . . . . . . . . . . . . . . . . . 254 7.1.1 Container Abilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 7.1.2 Container Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 7.1.3 Container Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 Contents xi 7.2 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 7.2.1 Abilitiesof Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 7.2.2 ArrayOperations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 7.2.3 Usingarray s as C-StyleArrays . . . . . . . . . . . . . . . . . . . . . . 267 7.2.4 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 7.2.5 TupleInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 7.2.6 Examples of UsingArrays . . . . . . . . . . . . . . . . . . . . . . . . . 268 7.3 Ve c t o r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 7.3.1 Abilitiesof Ve c t o r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 7.3.2 Ve c t o r Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273 7.3.3 UsingVe c t o r sas C-StyleArrays . . . . . . . . . . . . . . . . . . . . . . 278 7.3.4 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 7.3.5 Examples of UsingVe c t o r s . . . . . . . . . . . . . . . . . . . . . . . . . 279 7.3.6 Classvector . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 7.4 Deques. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 7.4.1 Abilitiesof Deques. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 7.4.2 Deque Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 7.4.3 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288 7.4.4 Examples of UsingDeques. . . . . . . . . . . . . . . . . . . . . . . . . 288 7.5 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 7.5.1 Abilitiesof Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 7.5.2 List Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 7.5.3 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 7.5.4 Examples of UsingLists . . . . . . . . . . . . . . . . . . . . . . . . . . 298 7.6 Forward Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 7.6.1 Abilitiesof Forward Lists . . . . . . . . . . . . . . . . . . . . . . . . . . 300 7.6.2 Forward List Operations . . . . . . . . . . . . . . . . . . . . . . . . . . 302 7.6.3 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 7.6.4 Examples of UsingForward Lists . . . . . . . . . . . . . . . . . . . . . . 312 7.7 Sets and Multisets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 7.7.1 Abilitiesof Sets and Multisets . . . . . . . . . . . . . . . . . . . . . . . 315 7.7.2 Setand MultisetOperations. . . . . . . . . . . . . . . . . . . . . . . . . 316 7.7.3 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 7.7.4 Examples of UsingSets and Multisets . . . . . . . . . . . . . . . . . . . 325 7.7.5 Example of Specifying the Sorting Criterion at Runtime . . . . . . . . . . 328 xii Contents 7.8 Mapsand Multimaps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 7.8.1 Abilitiesof Mapsand Multimaps. . . . . . . . . . . . . . . . . . . . . . 332 7.8.2 Map and Multimap Operations . . . . . . . . . . . . . . . . . . . . . . . 333 7.8.3 UsingMapsas Associative Arrays . . . . . . . . . . . . . . . . . . . . . 343 7.8.4 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 7.8.5 Examples of UsingMapsand Multimaps. . . . . . . . . . . . . . . . . . 345 7.8.6 Example with Maps,Strings,and Sorting Criterion at Runtime . . . . . . 351 7.9 UnorderedContainers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 7.9.1 Abilitiesof UnorderedContainers . . . . . . . . . . . . . . . . . . . . . 357 7.9.2 Creating and Controlling UnorderedContainers . . . . . . . . . . . . . . 359 7.9.3 OtherOperationsfor UnorderedContainers . . . . . . . . . . . . . . . . 367 7.9.4 The Bucket Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374 7.9.5 UsingUnorderedMapsas Associative Arrays . . . . . . . . . . . . . . . 374 7.9.6 ExceptionHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 7.9.7 Examples of UsingUnorderedContainers . . . . . . . . . . . . . . . . . 375 7.10 OtherSTL Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385 7.10.1 Strings as STL Containers . . . . . . . . . . . . . . . . . . . . . . . . . 385 7.10.2 Ordinary C-StyleArrays as STL Containers . . . . . . . . . . . . . . . . 386 7.11 Implementing ReferenceSemantics . . . . . . . . . . . . . . . . . . . . . . . . . 388 7.12 Whento Use WhichContainer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392 8 STL ContainerMembersin Detail 397 8.1 Type Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397 8.2 Create, Copy,and DestroyOperations . . . . . . . . . . . . . . . . . . . . . . . . 400 8.3 Nonmodifying Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 8.3.1 Size Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 8.3.2 Comparison Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 404 8.3.3 Nonmodifying Operationsfor Associative and UnorderedContainers . . . 404 8.4 Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 8.5 Direct ElementAccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408 8.6 Operationsto Generate Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . 410 8.7 Inserting and RemovingElements . . . . . . . . . . . . . . . . . . . . . . . . . . 411 8.7.1 Inserting Single Elements . . . . . . . . . . . . . . . . . . . . . . . . . . 411 8.7.2 Inserting MultipleElements . . . . . . . . . . . . . . . . . . . . . . . . . 416 8.7.3 RemovingElements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417 8.7.4 Resizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 Contents xiii 8.8 Special MemberFunctions for Lists and Forward Lists . . . . . . . . . . . . . . . 420 8.8.1 Special MemberFunctions for Lists (and Forward Lists) . . . . . . . . . 420 8.8.2 Special MemberFunctions for Forward Lists Only . . . . . . . . . . . . 423 8.9 Container Policy Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427 8.9.1 Nonmodifying Policy Functions . . . . . . . . . . . . . . . . . . . . . . 427 8.9.2 ModifyingPolicy Functions . . . . . . . . . . . . . . . . . . . . . . . . 428 8.9.3 Bucket Interface for UnorderedContainers . . . . . . . . . . . . . . . . . 429 8.10 Allocator Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430 8.10.1 FundamentalAllocator Members . . . . . . . . . . . . . . . . . . . . . . 430 8.10.2 Constructorswith Optional Allocator Parameters . . . . . . . . . . . . . 430 9 STL Iterators 433 9.1 Header Files for Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 9.2 Iterator Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 9.2.1 Output Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 9.2.2 Input Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 9.2.3 Forward Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436 9.2.4 BidirectionalIterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 9.2.5 Random-Access Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . 438 9.2.6 The Incrementand DecrementProblem of Ve c t o r Iterators . . . . . . . . 440 9.3 Auxiliary Iterator Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 9.3.1 advance() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 9.3.2 next()and prev(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 9.3.3 distance() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445 9.3.4 iter_swap() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446 9.4 Iterator Adapters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448 9.4.1 ReverseIterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448 9.4.2 Insert Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454 9.4.3 Stream Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460 9.4.4 MoveIterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466 9.5 Iterator Traits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466 9.5.1 WritingGenericFunctions for Iterators . . . . . . . . . . . . . . . . . . . 468 9.6 WritingUser-DefinedIterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471 xiv Contents 10 STL Function Objectsand UsingLambdas 475 10.1 The Conceptof Function Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 475 10.1.1 Function Objectsas Sorting Criteria . . . . . . . . . . . . . . . . . . . . 476 10.1.2 Function Objectswith Internal State . . . . . . . . . . . . . . . . . . . . 478 10.1.3 The Return Va l u eof for_each() . . . . . . . . . . . . . . . . . . . . . 482 10.1.4 Predicatesversus Function Objects. . . . . . . . . . . . . . . . . . . . . 483 10.2 PredefinedFunction Objectsand Binders . . . . . . . . . . . . . . . . . . . . . . 486 10.2.1 PredefinedFunction Objects . . . . . . . . . . . . . . . . . . . . . . . . 486 10.2.2 Function Adapters and Binders. . . . . . . . . . . . . . . . . . . . . . . 487 10.2.3 User-DefinedFunction Objectsfor Function Adapters . . . . . . . . . . . 495 10.2.4 Deprecated Function Adapters . . . . . . . . . . . . . . . . . . . . . . . 497 10.3 UsingLambdas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499 10.3.1 Lambdas versus Binders . . . . . . . . . . . . . . . . . . . . . . . . . . 499 10.3.2 Lambdas versus StatefulFunction Objects. . . . . . . . . . . . . . . . . 500 10.3.3 Lambdas Calling Global and MemberFunctions . . . . . . . . . . . . . . 502 10.3.4 Lambdas as HashFunction, Sorting,or Equivalence Criterion . . . . . . . 504 11 STL Algorithms 505 11.1 AlgorithmHeader Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 11.2 AlgorithmOverview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 11.2.1 A BriefIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506 11.2.2 Classification of Algorithms . . . . . . . . . . . . . . . . . . . . . . . . 506 11.3 Auxiliary Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517 11.4 The for_each()Algorithm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 11.5 Nonmodifying Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 11.5.1 Counting Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 11.5.2 Minimumand Maximum. . . . . . . . . . . . . . . . . . . . . . . . . . 525 11.5.3 SearchingElements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 11.5.4 Comparing Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542 11.5.5 Predicatesfor Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550 11.6 ModifyingAlgorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557 11.6.1 Copying Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557 11.6.2 MovingElements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561 11.6.3 Transforming and Combining Elements . . . . . . . . . . . . . . . . . . 563 11.6.4 Swapping Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566 11.6.5 AssigningNew Va l u e s . . . . . . . . . . . . . . . . . . . . . . . . . . . 568 11.6.6 ReplacingElements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571 Contents xv 11.7 RemovingAlgorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575 11.7.1 RemovingCertain Va l u e s . . . . . . . . . . . . . . . . . . . . . . . . . . 575 11.7.2 RemovingDuplicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578 11.8 Mutating Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583 11.8.1 Reversingthe Orderof Elements . . . . . . . . . . . . . . . . . . . . . . 583 11.8.2 Rotating Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584 11.8.3 PermutingElements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587 11.8.4 Shuffling Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589 11.8.5 MovingElements to the Front . . . . . . . . . . . . . . . . . . . . . . . 592 11.8.6 Partition into Two Subranges . . . . . . . . . . . . . . . . . . . . . . . . 594 11.9 Sorting Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596 11.9.1 Sorting AllElements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596 11.9.2 Partial Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599 11.9.3 Sorting Accordingto the n th Element . . . . . . . . . . . . . . . . . . . 602 11.9.4 HeapAlgorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604 11.10 Sorted-Range Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608 11.10.1SearchingElements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608 11.10.2MergingElements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614 11.11 Numeric Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623 11.11.1Processing Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623 11.11.2Converting Relativeand Absolute Va l u e s . . . . . . . . . . . . . . . . . . 627 12 SpecialContainers 631 12.1 Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632 12.1.1 The Core Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633 12.1.2 Example of UsingStacks . . . . . . . . . . . . . . . . . . . . . . . . . . 633 12.1.3 A User-DefinedStackClass. . . . . . . . . . . . . . . . . . . . . . . . . 635 12.1.4 Classstack in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . 637 12.2 Queues. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638 12.2.1 The Core Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639 12.2.2 Example of UsingQueues . . . . . . . . . . . . . . . . . . . . . . . . . 640 12.2.3 A User-DefinedQueue Class . . . . . . . . . . . . . . . . . . . . . . . . 641 12.2.4 Classqueue in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . 641 12.3 PriorityQueues. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641 12.3.1 The Core Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643 12.3.2 Example of UsingPriorityQueues. . . . . . . . . . . . . . . . . . . . . 643 12.3.3 Classpriority_queue in Detail . . . . . . . . . . . . . . . . . . . . 644 xvi Contents 12.4 Container Adapters in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645 12.4.1 Type Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645 12.4.2 Constructors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646 12.4.3 SupplementaryConstructorsfor PriorityQueues. . . . . . . . . . . . . . 646 12.4.4 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647 12.5 Bitsets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650 12.5.1 Examples of UsingBitsets . . . . . . . . . . . . . . . . . . . . . . . . . 651 12.5.2 Classbitsetin Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . 653 13 Strings 655 13.1 Purposeof the String Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656 13.1.1 A First Example: Extractinga Temporary Filename . . . . . . . . . . . . 656 13.1.2 A Second Example: ExtractingWordsand PrintingThemBackward . . . 660 13.2 Description of the String Classes . . . . . . . . . . . . . . . . . . . . . . . . . . 663 13.2.1 String Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663 13.2.2 OperationOverview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666 13.2.3 Constructorsand Destructor . . . . . . . . . . . . . . . . . . . . . . . . 667 13.2.4 Strings and C-Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668 13.2.5 Size and Capacity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669 13.2.6 ElementAccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671 13.2.7 Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672 13.2.8 Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673 13.2.9 Substringsand String Concatenation . . . . . . . . . . . . . . . . . . . . 676 13.2.10Input/Output Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 677 13.2.11Searchingand Finding . . . . . . . . . . . . . . . . . . . . . . . . . . . 678 13.2.12The Va l u enpos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680 13.2.13Numeric Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681 13.2.14Iterator Supportfor Strings . . . . . . . . . . . . . . . . . . . . . . . . . 684 13.2.15Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689 13.2.16Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 692 13.2.17Strings and Ve c t o r s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 692 13.3 String Classin Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693 13.3.1 Type Definitionsand StaticVa l u e s . . . . . . . . . . . . . . . . . . . . . 693 13.3.2 Create, Copy,and DestroyOperations . . . . . . . . . . . . . . . . . . . 694 13.3.3 Operationsfor Size and Capacity . . . . . . . . . . . . . . . . . . . . . . 696 13.3.4 Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697 13.3.5 Character Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699 13.3.6 GeneratingC-Strings and Character Arrays . . . . . . . . . . . . . . . . 700 Contents xvii 13.3.7 ModifyingOperations. . . . . . . . . . . . . . . . . . . . . . . . . . . . 700 13.3.8 Searchingand Finding . . . . . . . . . . . . . . . . . . . . . . . . . . . 708 13.3.9 Substringsand String Concatenation . . . . . . . . . . . . . . . . . . . . 711 13.3.10Input/Output Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 712 13.3.11Numeric Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713 13.3.12GeneratingIterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714 13.3.13Allocator Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715 14 RegularExpressions 717 14.1 The Regex Matchand Search Interface . . . . . . . . . . . . . . . . . . . . . . . 717 14.2 Dealingwith Subexpressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 720 14.3 Regex Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726 14.4 Regex Token Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727 14.5 ReplacingRegularExpressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 730 14.6 Regex Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732 14.7 Regex Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735 14.8 The Regex ECMAScriptGrammar . . . . . . . . . . . . . . . . . . . . . . . . . 738 14.9 OtherGrammars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739 14.10 BasicRegex Signaturesin Detail . . . . . . . . . . . . . . . . . . . . . . . . . . 740 15 Input/Output UsingStreamClasses 743 15.1 Common Background of I/O Streams . . . . . . . . . . . . . . . . . . . . . . . . 744 15.1.1 Stream Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744 15.1.2 Stream Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744 15.1.3 Global Stream Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 745 15.1.4 Stream Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745 15.1.5 Manipulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 746 15.1.6 A Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 746 15.2 FundamentalStream Classesand Objects. . . . . . . . . . . . . . . . . . . . . . 748 15.2.1 Classes and ClassHierarchy . . . . . . . . . . . . . . . . . . . . . . . . 748 15.2.2 Global Stream Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 751 15.2.3 Header Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752 15.3 Standard Stream Operators <> . . . . . . . . . . . . . . . . . . . . . . . . 753 15.3.1 Output Operator <> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754 15.3.3 Input/Output of Special Types . . . . . . . . . . . . . . . . . . . . . . . 755 xviii Contents 15.4 Stateof Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758 15.4.1 Constants for the Stateof Streams . . . . . . . . . . . . . . . . . . . . . 758 15.4.2 MemberFunctions Accessingthe Stateof Streams. . . . . . . . . . . . . 759 15.4.3 Stream Stateand BooleanConditions . . . . . . . . . . . . . . . . . . . 760 15.4.4 Stream Stateand Exceptions . . . . . . . . . . . . . . . . . . . . . . . . 762 15.5 Standard Input/Output Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 767 15.5.1 MemberFunctions for Input . . . . . . . . . . . . . . . . . . . . . . . . 768 15.5.2 MemberFunctions for Output . . . . . . . . . . . . . . . . . . . . . . . 771 15.5.3 Example Uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 772 15.5.4 sentryObjects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 772 15.6 Manipulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774 15.6.1 Overview of AllManipulators . . . . . . . . . . . . . . . . . . . . . . . 774 15.6.2 How ManipulatorsWork . . . . . . . . . . . . . . . . . . . . . . . . . . 776 15.6.3 User-DefinedManipulators. . . . . . . . . . . . . . . . . . . . . . . . . 777 15.7 Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779 15.7.1 Format Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779 15.7.2 Input/Output Format of BooleanVa l u e s . . . . . . . . . . . . . . . . . . 781 15.7.3 FieldWidth, Fill Character,and Adjustment . . . . . . . . . . . . . . . . 781 15.7.4 PositiveSign and UppercaseLetters . . . . . . . . . . . . . . . . . . . . 784 15.7.5 Numeric Base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785 15.7.6 Floating-Point Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . 787 15.7.7 GeneralFormatting Definitions . . . . . . . . . . . . . . . . . . . . . . . 789 15.8 Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 790 15.9 File Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791 15.9.1 File Stream Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791 15.9.2 Rvalue and MoveSemanticsfor File Streams . . . . . . . . . . . . . . . 795 15.9.3 File Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796 15.9.4 RandomAccess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799 15.9.5 UsingFile Descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . 801 15.10 Stream Classesfor Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802 15.10.1String Stream Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802 15.10.2MoveSemanticsfor String Streams. . . . . . . . . . . . . . . . . . . . . 806 15.10.3char* Stream Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807 15.11 Input/Output Operators for User-DefinedTypes . . . . . . . . . . . . . . . . . . . 810 15.11.1Implementing Output Operators . . . . . . . . . . . . . . . . . . . . . . 810 15.11.2Implementing Input Operators . . . . . . . . . . . . . . . . . . . . . . . 812 15.11.3Input/Output UsingAuxiliary Functions . . . . . . . . . . . . . . . . . . 814 Contents xix 15.11.4User-DefinedFormat Flags . . . . . . . . . . . . . . . . . . . . . . . . . 815 15.11.5Conventionsfor User-DefinedInput/Output Operators . . . . . . . . . . . 818 15.12 Connecting Input and Output Streams . . . . . . . . . . . . . . . . . . . . . . . . 819 15.12.1Loose Coupling Usingtie() . . . . . . . . . . . . . . . . . . . . . . . . 819 15.12.2TightCoupling UsingStream Buffers . . . . . . . . . . . . . . . . . . . 820 15.12.3Redirecting Standard Streams. . . . . . . . . . . . . . . . . . . . . . . . 822 15.12.4Streamsfor Readingand Writing. . . . . . . . . . . . . . . . . . . . . . 824 15.13 The Stream Buffer Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 826 15.13.1The Stream Buffer Interfaces . . . . . . . . . . . . . . . . . . . . . . . . 826 15.13.2Stream Buffer Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . 828 15.13.3User-DefinedStream Buffers . . . . . . . . . . . . . . . . . . . . . . . . 832 15.14 PerformanceIssues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844 15.14.1Synchronization with C’sStandard Streams . . . . . . . . . . . . . . . . 845 15.14.2Buffering in Stream Buffers . . . . . . . . . . . . . . . . . . . . . . . . . 845 15.14.3UsingStream Buffers Directly . . . . . . . . . . . . . . . . . . . . . . . 846 16 Internationalization 849 16.1 Character Encodingsand Character Sets . . . . . . . . . . . . . . . . . . . . . . . 850 16.1.1 Multibyte and Wide-CharacterText . . . . . . . . . . . . . . . . . . . . . 850 16.1.2 Different Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . 851 16.1.3 Dealingwith Character Sets in C++ . . . . . . . . . . . . . . . . . . . . 852 16.1.4 Character Traits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853 16.1.5 Internationalization of Special Characters . . . . . . . . . . . . . . . . . 857 16.2 The Conceptof Locales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857 16.2.1 UsingLocales. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858 16.2.2 Locale Facets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 864 16.3 Localesin Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866 16.4 Facets in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869 16.4.1 Numeric Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 870 16.4.2 Monetary Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 874 16.4.3 Timeand Date Formatting . . . . . . . . . . . . . . . . . . . . . . . . . 884 16.4.4 Character Classification and Conversion . . . . . . . . . . . . . . . . . . 891 16.4.5 String Collation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 904 16.4.6 Internationalized Messages . . . . . . . . . . . . . . . . . . . . . . . . . 905 xx Contents 17 Numerics 907 17.1 RandomNumbers and Distributions. . . . . . . . . . . . . . . . . . . . . . . . . 907 17.1.1 A First Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 908 17.1.2 Engines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 912 17.1.3 Enginesin Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 915 17.1.4 Distributions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 917 17.1.5 Distributionsin Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921 17.2 Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925 17.2.1 Classcomplex in General . . . . . . . . . . . . . . . . . . . . . . . . 925 17.2.2 Examples UsingClasscomplex . . . . . . . . . . . . . . . . . . . . . 926 17.2.3 Operationsfor Complex Numbers . . . . . . . . . . . . . . . . . . . . . 928 17.2.4 Classcomplex in Detail . . . . . . . . . . . . . . . . . . . . . . . . . 935 17.3 Global Numeric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 941 17.4 Va l a r r a y s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943 18 Concurrency 945 18.1 The High-Level Interface: async() and Futures . . . . . . . . . . . . . . . . . . 946 18.1.1 A First Example Usingasync() and Futures . . . . . . . . . . . . . . . 946 18.1.2 AnExample of Waitingfor Two Tasks . . . . . . . . . . . . . . . . . . . 955 18.1.3 Shared Futures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960 18.2 The Low-Level Interface: Threadsand Promises . . . . . . . . . . . . . . . . . . 964 18.2.1 Classstd::thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 964 18.2.2 Promises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 969 18.2.3 Classpackaged_task . . . . . . . . . . . . . . . . . . . . . . . . . . 972 18.3 Startinga Thread in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973 18.3.1 async() in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 974 18.3.2 Futuresin Detail. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 975 18.3.3 Shared Futuresin Detail. . . . . . . . . . . . . . . . . . . . . . . . . . . 976 18.3.4 Classstd::promise in Detail . . . . . . . . . . . . . . . . . . . . . . . 977 18.3.5 Classstd::packaged_task in Detail . . . . . . . . . . . . . . . . . . . 977 18.3.6 Classstd::thread in Detail . . . . . . . . . . . . . . . . . . . . . . . . 979 18.3.7 Namespace this_thread . . . . . . . . . . . . . . . . . . . . . . . . . 981 18.4 Synchronizing Threads, or the Problem of Concurrency . . . . . . . . . . . . . . 982 18.4.1 Bewareof Concurrency! . . . . . . . . . . . . . . . . . . . . . . . . . . 982 18.4.2 The Reason for the Problem of Concurrent Data Access . . . . . . . . . . 983 18.4.3 WhatExactlyCan GoWrong (the Extent of the Problem) . . . . . . . . . 983 18.4.4 The Features to Solvethe Problems . . . . . . . . . . . . . . . . . . . . . 987 Contents xxi 18.5 Mutexesand Locks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 989 18.5.1 UsingMutexesand Locks . . . . . . . . . . . . . . . . . . . . . . . . . . 989 18.5.2 Mutexesand Locks in Detail . . . . . . . . . . . . . . . . . . . . . . . . 998 18.5.3 Calling Oncefor MultipleThreads . . . . . . . . . . . . . . . . . . . . . 1000 18.6 ConditionVa r i a b l e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1003 18.6.1 Purposeof ConditionVa r i a b l e s . . . . . . . . . . . . . . . . . . . . . . . 1003 18.6.2 A First Complete Example for ConditionVa r i a b l e s . . . . . . . . . . . . 1004 18.6.3 UsingConditionVa r i a b l e s to Implement a Queue for MultipleThreads . . 1006 18.6.4 ConditionVa r i a b l e s in Detail . . . . . . . . . . . . . . . . . . . . . . . . 1009 18.7 Atomics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1012 18.7.1 Example of UsingAtomics . . . . . . . . . . . . . . . . . . . . . . . . . 1012 18.7.2 Atomicsand TheirHigh-Level Interface in Detail . . . . . . . . . . . . . 1016 18.7.3 The C-StyleInterface of Atomics . . . . . . . . . . . . . . . . . . . . . . 1019 18.7.4 The Low-Level Interface of Atomics . . . . . . . . . . . . . . . . . . . . 1019 19 Allocators 1023 19.1 UsingAllocatorsas an Application Programmer . . . . . . . . . . . . . . . . . . 1023 19.2 A User-DefinedAllocator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1024 19.3 UsingAllocatorsas a LibraryProgrammer . . . . . . . . . . . . . . . . . . . . . 1026 Bibliography 1031 Newsgroups and Forums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031 Books and Web Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1032 Index 1037 This page intentionally left blank

606

社区成员

发帖
与我相关
我的任务
社区描述
程序员。写过:移山之道,编程之美,构建之法,智能之门。
软件工程软件构建团队开发 企业社区 北京·朝阳区
社区管理员
  • SoftwareTeacher
  • GreyZeng
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧