modern-cpp-tutorial-en-us原版完整文件.docx
《modern-cpp-tutorial-en-us原版完整文件.docx》由会员分享,可在线阅读,更多相关《modern-cpp-tutorial-en-us原版完整文件.docx(89页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、Modern C+ Tutorial: C+11/14/17/20 On the FlyChangkun Ou (hiatchangkun.de)Last update: January 24, 2021NoticeThe content in this PDF file may outdated, please check our website or GitHub repository for the latest book updates.LicenseThis work was written by Ou Changkun and licensed under a Creative C
2、ommons Attribution-NonCommercial-NoDerivatives 4.0 International License. http:/creativecommons.org/licenses/by-nc-nd/4.0/2CONTENTSCONTENTSContents7Preface8Introduction8Targets8Purpose9Code9Exercises9Chapter 01: Towards Modern C+91.1 Deprecated Features101.2 Compatibilities with C11Further Readings1
3、3Chapter 02: Language Usability Enhancements132.1 Constants13nullptr13constexpr152.2 Variables and initialization17if-switch17Initializer list18Structured binding202.3 Type inference20auto20decltype22tail type inference23decltype(auto)242.4 Control flow25if constexpr25Range-based for loop252.5 Templ
4、ates26Extern templates26The “”26Type alias templates27Default template parameters28Variadic templates28Fold expression31Non-type template parameter deduction312.6 Object-oriented32Delegate constructor32Inheritance constructor33Explicit virtual function overwrite33override34final34Explicit delete def
5、ault function34Strongly typed enumerations35Conclusion36Exercises36Chapter 03: Language Runtime Enhancements373.1 Lambda Expression37Basics37Generic Lambda393.2 Function Object Wrapper40std:function40std:bind and std:placeholder413.3 rvalue Reference41lvalue, rvalue, prvalue, xvalue42rvalue referenc
6、e and lvalue reference43Move semantics45Perfect forwarding46Conclusion50Further Readings50Chapter 04 Containers504.1 Linear Container50std:array50std:forward_list524.2 Unordered Container524.3 Tuples54Basic Operations54Runtime Indexing55Merge and Iteration56Conclusion56Chapter 05 Smart Pointers and
7、Memory Management575.1 RAII and Reference Counting575.2 std:shared_ptr575.3 std:unique_ptr595.4 std:weak_ptr60Conclusion62Further Readings62Chapter 06 Regular Expression626.1 Introduction62Ordinary characters63Special characters63Quantifiers636.2 std:regex and Its Related64Conclusion66Exercise66Furt
8、her Readings68Chapter 07 Parallelism and Concurrency687.1 Basic of Parallelism687.2 Mutex and Critical Section687.3 Future707.4 Condition Variable717.5 Atomic Operation and Memory Model73Atomic Operation74Concistency Model76Memory Orders78Conclusion81Exercises81Further Readings81Chapter 08 File Syst
9、em818.1 Document and Link818.2 std:filesystem82Further Readings82Chapter 09 Minor Features829.1 New Type82long long int829.2 noexcept and Its Operations829.3 Literal84Raw String Literal84Custom Literal849.4 Memory Alignment85Conclusion86Chapter 10 Outlook: Introduction of C+2086Concept86Module87Cont
10、ract87Range87Coroutine87Conclusion87Further Readings87Appendix 1: Further Study Materials88Appendix 2: Modern C+ Best Practices88Common Tools88Coding Style88Overall Performance88Code Security88Maintainability89Portability89PREFACEPrefaceIntroductionC+ user group is fairly large. From the advent of C
11、+98 to the official finalization of C+11, it has accumulated over a decade. C+14/17 is an important complement and optimization for C+11, and C+20 brings this language to the door of modernization. The extended features of all these new standards are given to the C+ language. Infused with new vitali
12、ty. C+ programmers, who are still using traditional C+ (this book refers to C+98 and its previous C+ standards as traditional C+), may even amazed by the fact that they are not using the same language while reading modern C+ code.Modern C+ (this book refers to C+11/14/17/20) introduces a lot of feat
13、ures into traditional C+, which makes the whole C+ become language that modernized. Modern C+ not only enhances the usability of the C+ language itself, but the modification of the auto keyword semantics gives us more confidence in manipulating extremely complex template types. At the same time, a l
14、ot of enhancements have been made to the language runtime. The emergence of Lambda expressions has made C+ have the “closure” feature of “anonymous functions”, which is almost in modern programming languages (such as Python/Swift/. It has become commonplace, and the emergence of rvalue references ha
15、s solved the problem of temporary object efficiency that C+ has long been criticized.C+17 is the direction that has been promoted by the C+ community in the past three years. It also points out an important development direction of modern C+ programming. Although it does not appear as much as C+11,
16、it contains a large number of small and beautiful languages and features (such as structured binding), and the appearance of these features once again corrects our programming paradigm in C+.Modern C+ also adds a lot of tools and methods to its own standard library, such as std:thread at the level o
17、f the language itself, which supports concurrent programming and no longer depends on the underlying system on different platforms. The API implements cross-platform support at the language level; std:regex provides full regular expression support and more. C+98 has been proven to be a very successf
18、ul “paradigm”, and the emergence of modern C+ further promotes this paradigm, making C+ a better language for system programming and library development. Concepts provide verification on the compile-time of template parameters, further enhancing the usability of the language.In conclusion, as an adv
19、ocate and practitioner of C+, we always maintain an open mind to accept new things, and we can promote the development of C+ faster, making this old and novel language more vibrant.Targets This book assumes that readers are already familiar with traditional C+ (i.e. C+98 or earlier), at least they d
20、o not have any difficulty in reading traditional C+ code. In other words, those who have long experience in traditional C+ and people who desire to quickly understand the features8PurposeCHAPTER 01: TOWARDS MODERN C+of modern C+ in a short period of time are well suited to read the book; This book i
21、ntroduces to a certain extent of the dark magic of modern C+. However, these magics are very limited, they are not suitable for readers who want to learn advanced C+. The purpose of this book is offering a quick start for modern C+. Of course, advanced readers can also use this book to review and ex
22、amine themselves on modern C+.PurposeThe book claims “On the Fly”. Its intent is to provide a comprehensive introduction to the relevant features regarding modern C+ (before 2020s). Readers can choose interesting content according to the following table of content to learn and quickly familiarize th
23、e new features you would like to learn. Readers should aware that all of these features are not required. It should be learnt when you really need it.At the same time, instead of grammar-only, the book introduces the historical background as simple as possible of its technical requirements, which pr
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- modern cpp tutorial en us 原版 完整 文件
限制150内