C++20
C++20
About the Book
My book C++20 is both: a tutorial and reference to the C++20 standard. It teaches you C++20 and provides you with the details of this new thrilling C++ standard. The thrilling factor is mainly due to the big four of C++20.
- Concepts change the way we think and program templates. They are semantic categories for the template parameters. They enable you to express your intention directly in the type system. If something goes wrong, you get a clear error message.
- The new ranges library enables it to perform algorithms directly on the container, compose the algorithm with the pipe symbol, and apply them onto infinite data streams.
- Thanks to coroutines asynchronous programming in C++ becomes mainstream. Coroutines are the base for cooperative tasks, event loops, infinite data streams, or pipelines.
- Modules overcome the restrictions of header files. They promise a lot. For example, the separation of header and source files becomes as obsolete as the preprocessor. In the end, we have faster built time and an easier way to build packages.
Packages
The Book
Includes:
Source code
All source code examples
English
PDF
EPUB
MOBI
WEB
C++20 Team Edition: Five Copies
Get five copies to the price of three. This package includes all code examples.
Includes:
Source code
All source code examples
English
PDF
EPUB
MOBI
WEB
Reader Testimonials

Sandor Dargo
Senior Software Development Engineer at Amadeus
'C++ 20: Get the details' is exactly the book you need right now if you want to immerse yourself in the latest version of C++. It's a complete guide, Rainer doesn't only discuss the flagship features of C++20, but also every minor addition to the language. Luckily, the book includes tons of example code, so even if you don't have direct access yet to the latest compilers, you will have a very good idea of what you can expect from the different features. A highly recommended read!

Adrian Tam
Director of Data Science, Synechron Inc.
C++ has evolved a lot from its birth. With C++20, it is like a new language now. Surely this book is not a primer to teach you inheritance or overloading, but if you need to bring your C++ knowledge up to date, this is the right book. You will be surprised about the new features C++20 brought into C++. This book gives you clear explanations with concise examples. Its organization allows you to use it as a reference later. It can help you unleash the old language into its powerful future.
Table of Contents
-
- Reader Testimonials
-
Introduction
-
Conventions
- Special Fonts
- Special Boxes
-
Source Code
- Compilation of the Programs
- How should you read the Book?
-
Personal Notes
- Acknowledgments
- About Me
-
Conventions
-
About C++
-
1. Historical Context
- 1.1 C++98
- 1.2 C++03
- 1.3 TR1
- 1.4 C++11
- 1.5 C++14
- 1.6 C++17
-
2. Standardization
- 2.1 Stage 3
- 2.2 Stage 2
- 2.3 Stage 1
-
1. Historical Context
-
A Quick Overview of C++20
-
3. C++20
-
3.1 The Big Four
- 3.1.1 Concepts
- 3.1.2 Modules
- 3.1.3 The Ranges Library
- 3.1.4 Coroutines
-
3.2 Core Language
- 3.2.1 Three-Way Comparison Operator
- 3.2.2 Designated Initialization
-
3.2.3
consteval
andconstinit
- 3.2.4 Template Improvements
- 3.2.5 Lambda Improvements
- 3.2.6 New Attributes
-
3.3 The Standard Library
-
3.3.1
std::span
- 3.3.2 Container Improvements
- 3.3.3 Arithmetic Utilities
- 3.3.4 Calendar and Time Zones
- 3.3.5 Formatting Library
-
3.3.1
-
3.4 Concurrency
- 3.4.1 Atomics
- 3.4.2 Semaphores
- 3.4.3 Latches and Barriers
- 3.4.4 Cooperative Interruption
-
3.4.5
std::jthread
- 3.4.6 Synchronized Outputstreams
-
3.1 The Big Four
-
3. C++20
-
The Details
-
4. Core Language
-
4.1 Concepts
- 4.1.1 Two Wrong Approaches
- 4.1.2 Advantages of Concepts
- 4.1.3 The long, long History
- 4.1.4 Use of Concepts
- 4.1.5 Constrained and Unconstrained Placeholders
- 4.1.6 Abbreviated Function Templates
- 4.1.7 Predefined Concepts
- 4.1.8 Defining Concepts
- 4.1.9 Application
-
4.2 Modules
- 4.2.1 Why do we need Modules?
- 4.2.2 Advantages
- 4.2.3 A First Example
- 4.2.4 Compilation and Use
- 4.2.5 Export
- 4.2.6 Guidelines for a Module Structure
- 4.2.7 Module Interface Unit and Module Implementation Unit
- 4.2.8 Submodules and Module Partitions
- 4.2.9 Templates in Modules
- 4.2.10 Module Linkage
- 4.2.11 Header Units
-
4.3 Three-Way Comparison Operator
- 4.3.1 Ordering before C++20
- 4.3.2 Ordering since C++20
- 4.3.3 Comparision Categories
- 4.3.4 The Compiler-Generated Spaceship Operator
- 4.3.5 Rewriting Expressions
- 4.3.6 User-Defined and Auto-Generated Comparison Operators
-
4.4 Designated Initialization
- 4.4.1 Aggregate Initialization
- 4.4.2 Named Initialization of Class Members
-
4.5
consteval
andconstinit
-
4.5.1
consteval
-
4.5.2
constinit
- 4.5.3 Function Execution
- 4.5.4 Variable Initialization
- 4.5.5 Solving the Static Initialization Order Fiasco
-
4.5.1
-
4.6 Template Improvements
- 4.6.1 Conditionally Explicit Constructor
- 4.6.2 Non-Type Template Parameters
-
4.7 Lambda Improvements
- 4.7.1 Template Parameter for Lambdas
-
4.7.2 Detection of the Implicit Copy of the
this
Pointer - 4.7.3 Lambdas in an Unevaluated Context and Stateless Lambdas can be Default-Constructed and Copy-Assigned
-
4.8 New Attributes
-
4.8.1
[[nodiscard("reason")]]
-
4.8.2
[[likely]]
and[[unlikely]]
-
4.8.3
[[no_unique_address]]
-
4.8.1
-
4.9 Further Improvements
-
4.9.1
volatile
- 4.9.2 Range-based for loop with Initializers
-
4.9.3 Virtual
constexpr
function -
4.9.4 The new Character Type of UTF-8 Strings:
char8_t
-
4.9.5
using
enum
in Local Scopes - 4.9.6 Default Member Initializers for Bit Fields
-
4.9.1
-
4.1 Concepts
-
5. The Standard Library
-
5.1 The Ranges Library
- 5.1.1 The Concepts Ranges and Views
- 5.1.2 Direct on the Container
- 5.1.3 Function Composition
- 5.1.4 Lazy Evaluation
- 5.1.5 Define a View
- 5.1.6 A Flavor of Python
-
5.2
std::span
- 5.2.1 Static versus Dynamic Extent
- 5.2.2 Automatically Deduces the Size of a Contiguous Sequence of Objects
-
5.2.3 Create a
std::span
from a Pointer and a Size - 5.2.4 Modifying the Referenced Objects
-
5.2.5 Addressing
std::span
Elements - 5.2.6 A Constant Range of Modifiable Elements
-
5.3 Container Improvements
-
5.3.1
constexpr
Containers and Algorithms -
5.3.2
std::array
- 5.3.3 Consistent Container Erasure
-
5.3.4
contains
for Associative Containers - 5.3.5 String prefix and suffix checking
-
5.3.1
-
5.4 Arithmetic Utilities
- 5.4.1 Safe Comparison of Integers
- 5.4.2 Mathematical Constants
- 5.4.3 Midpoint and Linear Interpolation
- 5.4.4 Bit Manipulation
-
5.5 Calendar and Time Zones
- 5.5.1 Time of day
- 5.5.2 Calendar Dates
- 5.5.3 Time Zones
-
5.6 Formatting Library
- 5.6.1 Format String
- 5.6.2 User-Defined Types
-
5.7 Further Improvements
-
5.7.1
std::bind_front
-
5.7.2
std::is_constant_evaluated
-
5.7.3
std::source_location
-
5.7.1
-
5.1 The Ranges Library
-
6. Concurrency
-
6.1 Coroutines
- 6.1.1 A Generator Function
- 6.1.2 Characteristics
- 6.1.3 The Framework
- 6.1.4 Awaitables and Awaiters
- 6.1.5 The Workflows
-
6.1.6
co_return
-
6.1.7
co_yield
-
6.1.8
co_await
-
6.2 Atomics
-
6.2.1
std::atomic_ref
- 6.2.2 Atomic Smart Pointer
-
6.2.3
std::atomic_flag
Extensions -
6.2.4
std::atomic
Extensions
-
6.2.1
- 6.3 Semaphores
-
6.4 Latches and Barriers
-
6.4.1
std::latch
-
6.4.2
std::barrier
-
6.4.1
-
6.5 Cooperative Interruption
-
6.5.1
std::stop_token
,std::stop_callback
, andstd::stop_source
-
6.5.1
-
6.6
std::jthread
- 6.6.1 Automatically Joining
-
6.6.2 Cooperative Interruption of a
std::jthread
- 6.7 Synchronized Output Streams
-
6.1 Coroutines
-
7. Case Studies
-
7.1 Fast Synchronization of Threads
- 7.1.1 Condition Variables
-
7.1.2
std::atomic_flag
-
7.1.3
std::atomic<bool>
- 7.1.4 Semaphores
- 7.1.5 All Numbers
-
7.2 Variations of Futures
- 7.2.1 A Lazy Future
- 7.2.2 Execution on Another thread
-
7.3 Modification and Generalization of a Generator
- 7.3.1 Modifications
- 7.3.2 Generalization
-
7.4 Various Job Workflows
- 7.4.1 The Transparent Awaiter Workflow
- 7.4.2 Automatically Resuming the Awaiter
- 7.4.3 Automatically Resuming the Awaiter on a Separate Thread
-
7.1 Fast Synchronization of Threads
-
4. Core Language
- Epilogue
-
Further Information
-
8. C++23 and Beyond
-
8.1 C++23
- 8.1.1 The Coroutines Library
- 8.1.2 Modularized Standard Library for Modules
- 8.1.3 Executors
- 8.1.4 The Network Library
-
8.2 C++23 or Later
- 8.2.1 Contracts
- 8.2.2 Reflection
- 8.2.3 Pattern Matching
- 8.3 Further Information about C++23
-
8.1 C++23
- 9. Feature Testing
-
10. Glossary
- 10.1 Callable
- 10.2 Callable Unit
- 10.3 Concurrency
- 10.4 Critical Section
- 10.5 Data Race
- 10.6 Deadlock
- 10.7 Eager Evaluation
- 10.8 Executor
- 10.9 Function Objects
- 10.10 Lambda Expressions
- 10.11 Lazy Evaluation
- 10.12 Lock-free
- 10.13 Lost Wakeup
- 10.14 Math Laws
- 10.15 Memory Location
- 10.16 Memory Model
- 10.17 Non-blocking
- 10.18 Object
- 10.19 Parallelism
- 10.20 Predicate
- 10.21 RAII
- 10.22 Race Conditions
- 10.23 Regular
- 10.24 Scalar
- 10.25 SemiRegular
- 10.26 Spurious Wakeup
- 10.27 The Big Four
- 10.28 The Big Six
- 10.29 Thread
- 10.30 Time Complexity
- 10.31 Translation Unit
- 10.32 Undefined Behavior
- Index
-
8. C++23 and Beyond
Authors have earned$10,098,681writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
C++20
Rainer GrimmC++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
The book is almost daily updated. These incremental updates ease my interaction with the proofreaders.
A Guide to Artificial Intelligence in Healthcare
Dr. Bertalan MeskoCan we stay human in the age of A.I.? To go even further, can we grow in humanity, can we shape a more humane, more equitable and sustainable healthcare? This e-book aims to prepare healthcare and medical professionals for the era of human-machine collaboration. Read our guide to understanding, anticipating and controlling artificial intelligence.
Atomic Kotlin
Bruce Eckel and Svetlana IsakovaFor both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
Introducing EventStorming
Alberto BrandoliniThe deepest tutorial and explanation about EventStorming, straight from the inventor.
C++ Best Practices
Jason TurnerLevel up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Everyday Rails - RSpecによるRailsテスト入門
Junichi Ito (伊藤淳一), AKIMOTO Toshiharu, 魚振江, and Aaron SumnerRSpecを使ってRailsアプリケーションに信頼性の高いテストを書く実践的なアドバイスを提供します。詳細で丁寧な説明は本書のオリジナルコンテンツです。また、説明には実際に動かせるサンプルアプリケーションも使用します。本書は2017年版にアップデートされ、RSpec 3.6やRails 5.1といった新しい環境に対応しています!さあ、自信をもってテストできるようになりましょう!
The Hundred-Page Machine Learning Book
Andriy BurkovEverything you really need to know in Machine Learning in a hundred pages.
Composing Software
Eric ElliottAll software design is composition: the act of breaking complex problems down into smaller problems and composing those solutions. Most developers have a limited understanding of compositional techniques. It's time for that to change.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Top Bundles
- #1
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon... - #3
Cisco CCNA 200-301 Complet
4 Books
Ce lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301. - #4
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité... - #5
Learn Git, Bash, and Terraform the Hard Way
3 Books
Learn Git, Bash and Terraform using the Hard Way method.These technologies are essential tools in the DevOps armoury. These books walk you through their features and subtleties in a simple, gradual way that reinforces learning rather than baffling you with theory. - #6
PowerShell
3 Books
Buy every PowerShell book from Adam Bertram at a 20% discount! - #7
Software Architecture and Beautiful APIs
2 Books
There is no better way to learn how to design good APIs than to look at many existing examples, complementing the Software Architecture theory on API design. - #8
9 Books-Bundle: Shut Up and Code!
9 Books
"Shut up and code." Laughter in the audience. The hacker had just plugged in his notebook and started sharing his screen to present his super-smart Python script. "Shut up and code" The letters written in a white literal coding font on black background was the hackers' home screen background mantra. At the time, I was a first-year computer... - #9
CCDE Practical Studies (All labs)
3 Books
CCDE lab - #10
Modern C++ by Nicolai Josuttis
2 Books