C++20
C++20
About the Book
My book C++20 is a tutorial and a reference for 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 and 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 to infinite data streams.
- Thanks to coroutines, asynchronous programming in C++ has become 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 obsolete as the preprocessor. In the end, we have faster built time and an easier way to build packages.
Packages
The Book
PDF
EPUB
WEB
English
C++20 Team Edition: Five Copies
Get five copies to the price of three. This package includes all code examples.
PDF
EPUB
WEB
English
Bundles that include this book
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.

Harishankar Yadav
Full-time independent Trainer and Mentor for C++ and OOPs, Guidelines, and best practices.
A great work by Rainer and a fantastic book on C++20. With Lots of easy-to-understand, grasp code examples. I have never thought that I will have such a wonderful book covering everything about C++20 with great details and easy language. I am sure this book will change the perception about C++ at all levels of C++ programmers. A must-have book on C++20 on your desk.
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 Formatting Library
- 3.3.5 Calendar and Time Zones
-
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 Define Concepts
- 4.1.9 Requires Expressions
- 4.1.10 User-Defined Concepts
-
4.2 Modules
- 4.2.1 Why do we need Modules?
- 4.2.2 Advantages
- 4.2.3 A First Example
- 4.2.4 Compiler Support
- 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
Private
Module Fragment - 4.2.9 Submodules and Module Partitions
- 4.2.10 Templates in Modules
- 4.2.11 Module Linkage
- 4.2.12 Header Units
- 4.2.13 Macros
- 4.2.14 Migrating from Headers to Modules
-
4.3 Equality Comparison and Three-Way Comparison
- 4.3.1 Comparison before C++20
- 4.3.2 Comparison since C++20
- 4.3.3 Comparison Categories
- 4.3.4 Compiler-Generated Equality and 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 Comparison of
const
,constexpr
,consteval
, andconstinit
- 4.5.4 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 (NTTP)
-
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.7.4 Pack Expansion in Init-Capture
-
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 Ranges
- 5.1.2 Views
- 5.1.3 Range Adaptors
- 5.1.4 Direct on the Container
- 5.1.5 Function Composition
- 5.1.6 Lazy Evaluation
- 5.1.7 Define a View
-
5.1.8
std
Algorithms versusstd::ranges
Algorithms - 5.1.9 A Flavor of Python
-
5.2
std::span
- 5.2.1 Static versus Dynamic Extent
- 5.2.2 Creation
- 5.2.3 Automatically Deduces the Size of a Contiguous Sequence of Objects
- 5.2.4 Modifying the Referenced Objects
-
5.2.5 Addressing
std::span
Elements - 5.2.6 A Constant Range of Modifiable Elements
-
5.2.7 Dangers of
std::span
-
5.3 Container and Algorithm 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 Shift the Content of a Container
- 5.3.6 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 Formatting Library
- 5.5.1 Format String
- 5.5.2 User-Defined Types
-
5.6 Calendar and Time Zones
- 5.6.1 Basic Chrono Terminology
- 5.6.2 Basic Types and Literals
- 5.6.3 Time of day
- 5.6.4 Calendar Dates
- 5.6.5 Time Zones
- 5.6.6 Chrono I/O
-
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.4
std::to_address
-
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_source
-
6.5.2
std::stop_token
-
6.5.3
std::stop_callback
- 6.5.4 A General Mechanism to Send Signals
- 6.5.5 Joining Threads
-
6.5.6 New
wait
Overloads for thecondition_variable_any
-
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 Aggregate
- 10.2 Automatic Storage Duration
- 10.3 Callable
- 10.4 Callable Unit
- 10.5 Concurrency
- 10.6 Critical Section
- 10.7 Data Race
- 10.8 Deadlock
- 10.9 Dynamic Storage Duration
- 10.10 Eager Evaluation
- 10.11 Executor
- 10.12 Function Objects
- 10.13 Lambda Expressions
- 10.14 Lazy Evaluation
- 10.15 Literal Type
- 10.16 Lock-free
- 10.17 Lost Wakeup
- 10.18 Math Laws
- 10.19 Memory Location
- 10.20 Memory Model
- 10.21 Non-blocking
- 10.22 Object
- 10.23 Parallelism
- 10.24 POD (Plain Old Data)
- 10.25 Predicate
- 10.26 RAII
- 10.27 Race Conditions
- 10.28 Regular Type
- 10.29 Scalar Type
- 10.30 SemiRegular
- 10.31 Short-Circuit Evaluation
- 10.32 Standard-Layout Type
- 10.33 Static Storage Duration
- 10.34 Spurious Wakeup
- 10.35 The Big Four
- 10.36 The Big Six
- 10.37 Thread
- 10.38 Thread Storage Duration
- 10.39 Time Complexity
- 10.40 Translation Unit
- 10.41 Trivial Type
- 10.42 Undefined Behavior
- Index
-
8. C++23 and Beyond
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned$12,307,240writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
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) and EPUB (for phones, tablets and 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
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Personal Finance
Jason AndersonThis textbook provides an in-depth analysis on personal finance that is both practical and straightforward in its approach. It has been written in such a way that the readers can gain knowledge without getting overwhelmed by the technical terms. Suitable for both beginners and advanced learners.
Getting to Know IntelliJ IDEA
Trisha Gee and Helen ScottIf we treat our IDE as a text editor, we are doing ourselves a disservice. Using a combination of tutorials and a questions-and-answers approach, Getting to Know IntelliJ IDEA will help you find ways to use IntelliJ IDEA that enable you to work comfortably and productively as a professional developer.
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.
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
Stats One
William FooteMachine Learning Q and AI
Sebastian Raschka, PhDHave you recently completed a machine learning or deep learning course and wondered what to learn next? With 30 questions and answers on key concepts in machine learning and AI, this book provides bite-sized bits of knowledge for your journey to becoming a machine learning expert.
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.
Gradual Modularization for Ruby and Rails
Stephan HagemannGet yourself a new tool to manage your Rails application and your growing engineering organization! Prevent the ball-of-mud (and fix it!). Go for microservices or SOA if it makes sense not just because you don't have any other tool. Do all this through a low-overhead tool: packages. Enable better conversations to make practical changes today.
Top Bundles
- #1
Software Architecture
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
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #3
1500 QUIZ COMMENTATI (3 libri)
3 Books
Tre libri dei QUIZ MMG Commentati al prezzo di DUE! I QUIZ dei concorsi ufficiali di Medicina Generale relativi agli anni: 2000-2001-2003-2012-2013-2014-2015-2016-2017-2018-2019-2020-2021 +100 inediti Raccolti in unico bundle per aiutarvi nello studio e nella preparazione al concorso. All'interno di ogni libro i quiz sono stati suddivisi per... - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #5
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #7
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é... - #9
Development and Deployment of Multiplayer Online Games, Part ARCH. Architecture (Vol. I-III)
3 Books
What's the Big Idea? The idea behind this book is to summarize the body of knowledge that already exists on multiplayer games but is not available in one single place.And quite a fewof the issues discussed within this series (planned as three nine volumes ~300 pages each), while known in the industry, have not been published at all (except for... - #10
Modern C++ Collection
3 Books
Get All about Modern C++C++ Standard Library, including C++20Concurrency with Modern C++, including C++20C++20Each book has about 200 complete code examples. Updates are included. When I update one of the books, you immediately get the updated bundle. You can expect significant updates to each new C++ standard (C++23, C++26, .. ) and also...