Programming with C++20
Programming with C++20
Concepts, Coroutines, Ranges, and more
About the Book
Programming with C++20 teaches programmers with C++ experience the new features of C++20 and how to apply them. It does so by assuming C++11 knowledge. Elements of the Standards between C++11 and C++20 will be briefly introduced, if necessary. However, the focus is on teaching the elements of C++20.
Reach out to me if you like to be a reviewer. As an accepted reviewer, you get a free copy of the book.
Table of Contents
- 1 Concepts: Predicates for strongly typed generic code
- 1.1 Programming before Concepts
- 1.1.1 The
enable_if
requirement - 1.1.2 Long error messages from template errors
- 1.1.1 The
- 1.2 What are Concepts
- 1.2.1 Thinking in concepts
- 1.2.2 Concepts and types
- 1.3 The anatomy of a concept
- 1.4 Existing Concepts
- 1.5 The requires-clause: The runway for Concepts
- 1.6 The requires-expression
- 1.6.1 Simple requirement
- 1.6.2 Nested requirement
- 1.6.3 Compound requirement
- 1.6.4 Type requirement
- 1.6.5 Complete constrained version of
add
- 1.7 Adding Concepts to make requirements reusable
- 1.8 Testing requirements
- 1.9 Using a Concept
- 1.9.1 Using a
constexpr
function in a concept - 1.9.2 Applying a concept with a requires-clause
- 1.9.3 Applying a concept with a trailing requires-clause
- 1.9.4 Applying a concept as a type-constraint
- 1.9.1 Using a
- 1.10 Abbreviated function template with
auto
as generic parameter- 1.10.1 What does such a construct do?
- 1.10.2 Exemplary use case: Requiring a parameter type to be an invocable
- 1.11 Concepts and constrained
auto
types- 1.11.1 Constrained
auto
variables - 1.11.2 Constrained
auto
return-type
- 1.11.1 Constrained
- 1.12 The power of Concepts:
requires
instead ofenable_if
- 1.12.1 Call method based in requires
- 1.12.2 Conditional copy operations
- 1.12.3 Conditional destructor
- 1.12.4 Conditional methods
- 1.13 Concepts ordering
- 1.13.1 Subsumption rules details
- 1.13.2 One more thing, never say not
- 1.14 Improved error message
- 1.1 Programming before Concepts
- 2 Coroutines
- 2.1 Regular functions and their control flow
- 2.2 What are Coroutines
- 2.2.1 Generating a sequence with coroutines
- 2.3 The elements of Coroutines in C++
- 2.3.1 Stackless Coroutines in C++
- 2.3.2 The new kids on the block:
co_await
,co_return
andco_yield
- 2.3.3 The generator
- 2.3.4 The
promise_type
- 2.3.5 An iterator for
generator
- 2.3.6 Coroutine customization points
- 2.3.7 Coroutines restrictions
- 2.4 Writing a byte stream parser the old way
- 2.5 A byte stream parser with Coroutines
- 2.5.1 Writing the
Parse
function as coroutine - 2.5.2 Creating an Awaitable type
- 2.5.3 A more flexible
promise_type
- 2.5.4 Another generator the FSM
- 2.5.5 Simulating a network byte stream
- 2.5.6 Plugging the pieces together
- 2.5.1 Writing the
- 2.6 A different strategy of the
Parse
generator - 2.7 Using a coroutine with custom
new
/delete
- 2.8 Using a coroutine with a custom allocator
- 2.9 Exceptions in coroutines
- 4
std::ranges
- 5 Modules
- 5 std::format: Modern & type-safe text formatting
- 5.1 Formatting a string before C++20
- 5.1.1 Formatting a stock index with
iostreams
- 5.1.2 Formatting a stock index with
printf
- 5.1.1 Formatting a stock index with
- 5.2 Formatting a string using
std::format
- 5.2.1
std::format
specifiers - 5.2.2 Escaping
- 5.2.3 Localization
- 5.2.4 Formatting floating-point numbers
- 5.2.1
- 5.3 Formatting a custom type
- 5.3.1 Writing a custom formatter
- 5.3.2 Parsing a custom format specifier
- 5.4 Referring to a format argument
- 5.5 Using a custom buffer
- 5.5.1 Formatting into a dynamically sized buffer
- 5.5.2 Formatting into a fixed sized buffer
- 5.6 Writing our own logging function
- 5.6.1 Prefer
make_format_args
when forwarding an argument pack - 5.6.2 Create the format specifier at compile-time
- 5.6.3 Formatting the time
- 5.6.1 Prefer
- 5.1 Formatting a string before C++20
- 6 Three-way comparisons: Simplify your comparisons
- 6.1 Writing a class with equal comparison
- 6.1.1 Comparing different types
- 6.1.2 Less hand-written code with operator reverse, rewrite and
=default
- 6.2 Writing a class with ordering comparison pre C++20
- 6.3 Writing a class with ordering comparison in C++20
- 6.3.1 Member-wise comparison with
=default
- 6.3.1 Member-wise comparison with
- 6.4 The different comparison categories
- 6.4.1 The comparison categories
- 6.4.2 The comparison strength:
strong
orweak
- 6.4.3 Another comparison strength: partial ordering
- 6.4.4 Named comparison functions
- 6.5 Converting between comparison categories
- 6.6 New operator abilities: reverse and rewrite
- 6.7 The power of the default spaceship
- 6.8 Applying a custom sort order
- 6.9 Spaceship-operator interaction with existing code
- 6.1 Writing a class with equal comparison
- 7 Lambdas in C++20: New features
- 7.1 [=, this] as a lambda capture
- 7.2 Default constructible lambdas
- 7.3 Captureless lambdas in unevaluated contexts
- 7.4 Lambdas in generic code
- 7.4.1 Lambdas with templated-head
- 7.4.2 Variadic lambda arguments
- 7.4.3 Forwarding variadic lambda arguments
- 7.5 Pack expansions in lambda init-captures
- 7.6 Restricting lambdas with Concepts
- 8 Aggregate initialization
- 8.1 What is an aggregate
- 8.2 Designated initializers
- 8.2.1 Designated initializers in C
- 8.2.2 Designated initializers in C++20
- 8.2.3 Initializing a subset of an aggregate with designated initializers
- 8.2.4 Initialize a subset with designated initializers without in-class member initializers
- 8.2.5 Named arguments in C++: Aggregates with designated initializers
- 8.2.6 Overload resolution and designated initializers
- 8.3 Direct-initialization for aggregates
- 8.3.1 Initialization forms: Braced or parenthesis initialization
- 8.3.2 Aggregates with user-declared constructors
- 8.4 Class Template Argument Deduction for aggregates
- 9 Class-types as non-type template parameters
- 9.1 What are non-type template parameters again
- 9.2 The requirements for class types as non-type template parameters
- 9.3 Class types as non-type template parameters
- 9.3.1 A first contact with class types as NTTP
- 9.3.2 What compile-time data do we have
- 9.4 Building a format function with specifier count check
- 9.4.1 A first
print
function - 9.4.2 Optimizing the format string creation
- 9.4.3 Checking the number of specifiers in a format string
- 9.4.4 Checking if type and specifiers do match
- 9.4.5 Enable more use-cases and prevent mistakes
- 9.4.1 A first
- 10 New STL elements
- 10.1
bit_cast
: Reinterpreting your objects - 10.2
endian
: Endianess detection at compile time - 10.3
to_array
- 10.4
span
: A view of continuous memory - 10.5
source_location
: The modern way of__FUNCTION__
- 10.5.1 Writing a custom assert function
- 10.5.2 Writing a custom assert function with C++20
- 10.5.3 Writing a custom log function with C++20
- 10.6
contains
for all associative containers - 10.7
start_with
ends_with
forstd::string
- 10.1
- 11 Language Updates
- 12 Doing (more) things at compile-time
- Acronyms
- Bibliography
- Index
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