没有合适的资源?快使用搜索试试~ 我知道了~
首页C++17 The Complete Guide.pdf
C++17 The Complete Guide.pdf
需积分: 47 75 下载量 25 浏览量
更新于2023-05-12
评论 1
收藏 2.11MB PDF 举报
C++17 - The Complete Guide by Nicolai M. Josuttis Giving guidance on how to use Language and Library Features of C++17 For programmers, who want to switch to the latest version of Modern C++
资源详情
资源评论
资源推荐
Josuttis: C++17 2019/02/16 18:57 page i
Nicolai M. Josuttis
C++17 - The Complete Guide
Josuttis: C++17 2019/02/16 18:57 page ii
C++17 - The Complete Guide
Nicolai M. Josuttis
This book is for sale at http://leanpub.com/cpp17.
This version was published on 2019/02/16.
This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publish-
ing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight
tools and many iterations to get reader feedback, pivot until you have the right book and
build traction once you do.
© 2019 by Nicolai Josuttis. All rights reserved.
This book was typeset by Nicolai M. Josuttis using the L
A
T
E
X document processing system.
Josuttis: C++17 2019/02/16 18:57 page iii
Contents
Preface xiii
Versions of This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv
About This Book xvii
What You Should Know Before Reading This Book . . . . . . . . . . . . . . . . . . . . . . xvii
Overall Structure of the Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
How to Read This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
The C++17 Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Example Code and Additional Information . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Part I: Basic Language Features 1
1 Structured Bindings 3
1.1 Structured Bindings in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Where Structured Bindings can be Used . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.1 Structures and Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.2 Raw Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.3 std::pair, std::tuple, and std::array . . . . . . . . . . . . . . . . . . . 9
1.3 Providing a Tuple-Like API for Structured Bindings . . . . . . . . . . . . . . . . . . . . 11
1.4 Afternotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2 if and switch with Initialization 19
2.1 if with Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
iii
Josuttis: C++17 2019/02/16 18:57 page iv
iv Contents
2.2 switch with Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.3 Afternotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3 Inline Variables 23
3.1 Motivation of Inline Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.2 Using Inline Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.3 constexpr now implies inline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.4 Inline Variables and thread_local . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.5 Afternotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4 Aggregate Extensions 31
4.1 Motivation for Extended Aggregate Initialization . . . . . . . . . . . . . . . . . . . . . . 32
4.2 Using Extended Aggregate Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.3 Definition of Aggregates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.4 Backward Incompatibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.5 Afternotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5 Mandatory Copy Elision or Passing Unmaterialized Objects 37
5.1 Motivation for Mandatory Copy Elision for Temporaries . . . . . . . . . . . . . . . . . 37
5.2 Benefit of Mandatory Copy Elision for Temporaries . . . . . . . . . . . . . . . . . . . . 39
5.3 Clarified Value Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
5.3.1 Value Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
5.3.2 Value Categories Since C++17 . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
5.4 Unmaterialized Return Value Passing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5.5 Afternotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6 Lambda Extensions 45
6.1 constexpr Lambdas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6.2 Passing Copies of this to Lambdas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
6.3 Capturing by Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
6.4 Afternotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7 New Attributes and Attribute Features 51
7.1 Attribute [[nodiscard]] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Josuttis: C++17 2019/02/16 18:57 page v
Contents v
7.2 Attribute [[maybe_unused]] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.3 Attribute [[fallthrough]] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7.4 General Attribute Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
7.5 Afternotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8 Other Language Features 57
8.1 Nested Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
8.2 Defined Expression Evaluation Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.3 Relaxed Enum Initialization from Integral Values . . . . . . . . . . . . . . . . . . . . . 61
8.4 Fixed Direct List Initialization with auto . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.5 Hexadecimal Floating-Point Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.6 UTF-8 Character Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.7 Exception Specifications as Part of the Type . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.8 Single-Argument static_assert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
8.9 Preprocessor Condition __has_include . . . . . . . . . . . . . . . . . . . . . . . . . . 69
8.10 Afternotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Part II: Template Features 71
9 Class Template Argument Deduction 73
9.1 Usage of Class Template Argument Deduction . . . . . . . . . . . . . . . . . . . . . . . 74
9.1.1 Copying by Default . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
9.1.2 Deducing the Type of Lambdas . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
9.1.3 No Partial Class Template Argument Deduction . . . . . . . . . . . . . . . . . 77
9.1.4 Class Template Argument Deduction Instead of Convenience Functions . . 78
9.2 Deduction Guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
9.2.1 Using Deduction Guides to Force Decay . . . . . . . . . . . . . . . . . . . . . 81
9.2.2 Non-Template Deduction Guides . . . . . . . . . . . . . . . . . . . . . . . . . . 81
9.2.3 Deduction Guides versus Constructors . . . . . . . . . . . . . . . . . . . . . . . 82
9.2.4 Explicit Deduction Guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
9.2.5 Deduction Guides for Aggregates . . . . . . . . . . . . . . . . . . . . . . . . . . 83
9.2.6 Standard Deduction Guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
9.3 Afternotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
剩余389页未读,继续阅读
caohongfei881
- 粉丝: 8
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0