C++20 - The Complete Guide
$9.80
Minimum price
$24.80
Suggested price

C++20 - The Complete Guide

About the Book

C++20 is the next evolution in modern C++ programming, which will be supported step-by-step by the latest version of gcc, clang, and Visual C++.

C++20 is a big step, maybe even larger than C++11.

It contains a couple of new key features (modules, concepts, ranges, corountines) plus several small but valuable language and library features, which will change the way we program in C++. As usual, not everything is self-explanatory, combining new features gives even more power, and there are hidden traps.

This book presents all the new language and library features of C++20. It covers the motivation and context of each new feature with examples and background information. The focus is on how these features impact day-to-day programming, what it means to combine them, and how to benefit from this in practice.

Buy early, pay less, free updates

Note that this book is published step-by-step. It started with just a few pages not published yet. As soon I have significant content, a first version will be published. Then, the contents grows with new chapters, examples, and caveats about the features of C++20 and I integrate all feedback I get for the pages already published.

See cppstd20.com for a detailed list of covered topics.

As written, once you bought it you will get all updates for free.

PDF versus Other Formats

I write the book in LaTeX and generate PDF from it (the way I wrote my other books). The other formats (epub, mobi, and online reading) come from the leanpub markdown interface, for which I generate the necessary input from LaTeX by script.

Thus, the PDF layout has a better quality than the other formats. For example, the syntax highlighting rules for the formats other than PDF have to get fixed as soon as possible and the index is missing yet. Leanpub and me are working on corresponding improvements.

I hope you enjoy and benefit.

Nico

#cpp20tcg

About the Author

Nicolai M. Josuttis
Nicolai M. Josuttis

Nicolai Josuttis (http://www.josuttis.com) is well known in the programming community because he not only speaks and writes with authority, being the (co-)author of the world-wide best sellers

but is also an innovative presenter, having talked at various conferences and events.

He is an independent trainer and speaker being active in C++ standardization for more than 20 years.

Table of Contents

  • 1. Preface
    • 1.1 An Experiment
    • 1.2 Versions of This Book
    • 1.3 Acknowledgments
  • 2. About This Book
    • 2.1 What You Should Know Before Reading This Book
    • 2.2 Overall Structure of the Book
    • 2.3 How to Read This Book
    • 2.4 The Way I Implement
      • 2.4.1 Initializations
      • 2.4.2 Error Terminology
      • 2.4.3 Code Simplifications
    • 2.5 The C++ Standards
    • 2.6 Example Code and Additional Information
    • 2.7 Feedback
  • 3. Comparisons and Operator <=>
    • 3.1 Motivation for Operator<=>
      • 3.1.1 Defining Comparison Operators Before C++20
      • 3.1.2 Defining Comparison Operators Since C++20
    • 3.2 Defining and Using Comparisons
      • 3.2.1 Using Operator<=>
      • 3.2.2 Comparison Category Types
      • 3.2.3 Using Comparison Categories with operator<=>
      • 3.2.4 Calling operator<=>
      • 3.2.5 Dealing with Multiple Ordering Criteria
    • 3.3 Defining operator<=> and operator==
      • 3.3.1 Defaulted operator<=>
      • 3.3.2 Defaulted operator<=> and Inheritance
    • 3.4 Overload Resolution with Rewritten Expressions
    • 3.5 Afternotes
  • 4. Basic Extensions for Generic Functions
    • 4.1 auto for Parameters of Ordinary Functions
      • 4.1.1 auto for Parameters of Member Functions
      • 4.1.2 auto Functions versus Lambdas
      • 4.1.3 auto for Parameters in Detail
    • 4.2 Template Syntax for Generic Lambdas
    • 4.3 Afternotes
  • 5. Concepts and Requirements
    • 5.1 Motivating Example of Concepts and Requirements
      • 5.1.1 Improving the Template Step-by-Step
      • 5.1.2 The Whole Resulting Program
    • 5.2 Typical Application of Concepts and Requirements in Practice
      • 5.2.1 Requirements to Understand Code and Error Messages
      • 5.2.2 Requirements to Disable Generic Code
      • 5.2.3 Requirements to Use Different Statements
      • 5.2.4 The Example as a Whole
      • 5.2.5 Former Workarounds
    • 5.3 Constraints and Requirements in Detail
      • 5.3.1 Constraints
      • 5.3.2 Ad hoc Boolean Expressions
      • 5.3.3 requires Expressions
    • 5.4 Concepts in Detail
      • 5.4.1 Defining Concepts
      • 5.4.2 Special Abilities of Concepts
      • 5.4.3 Using Concepts as Type Constraints
    • 5.5 Subsuming Constraints and Concepts
      • 5.5.1 Indirect Subsumptions
    • 5.6 Design Guidelines for Concepts
      • 5.6.1 Dealing with Multiple Requirements
      • 5.6.2 Concepts versus Traits and Expressions
      • 5.6.3 When to Use if constexpr
    • 5.7 Other Stuff of Concepts
    • 5.8 Afternotes
  • 6. Standard Concepts
    • 6.1 Language-Related Concepts
      • 6.1.1 Object Concepts
      • 6.1.2 Arithmetic Concepts
      • 6.1.3 Concepts for Pointers-Like Objects
      • 6.1.4 Iterator Concepts
      • 6.1.5 Range Concepts
      • 6.1.6 Iterator Concepts for Algorithms
      • 6.1.7 Concepts for Callables
    • 6.2 Supporting Type Functions
    • 6.3 Afternotes
  • 7. Ranges and Views
    • 7.1 A Tour of Ranges by Examples
      • 7.1.1 Passing Containers to Algorithms as Ranges
      • 7.1.2 Algorithms with Requirements
      • 7.1.3 Definition of Ranges
      • 7.1.4 Sentinels and Subranges
      • 7.1.5 Projections
      • 7.1.6 Borrowed Ranges and Iterators
      • 7.1.7 Utilities to Implement Code for Ranges
      • 7.1.8 Limitations and Drawbacks of Ranges
    • 7.2 Views
      • 7.2.1 Views from Ranges
    • 7.3 Pipelines of Views
      • 7.3.1 Range Adaptors
      • 7.3.2 Pipelines for Temporary Ranges
      • 7.3.3 Lazy Evaluation
      • 7.3.4 Performance Issues with Filters
      • 7.3.5 Views and Pipelines with Write Access
      • 7.3.6 Write Access with Filter Views
      • 7.3.7 Generic Code should not Take Ranges by const Reference
    • 7.4 Open
    • 7.5 Afternotes
  • 8. Ranges in Detail
    • 8.1 Range Utilities
    • 8.2 Other General Utilities for Ranges
      • 8.2.1 std::unreachable_sentinel
    • 8.3 Open
    • 8.4 Afternotes
  • 9. Views in Detail
    • 9.1 Overview of all Views
    • 9.2 Subset Views
      • 9.2.1 std::ranges::subrange
    • 9.3 Filtering and Transforming Views
      • 9.3.1 Filter View
      • 9.3.2 Join View
      • 9.3.3 Split View
    • 9.4 Transforming Views
    • 9.5 Mutating Views
      • 9.5.1 std::ranges::reverse_view
    • 9.6 Generating Views
      • 9.6.1 std::ranges::iota_view
    • 9.7 Open
    • 9.8 Afternotes
  • 10. Spans
    • 10.1 Using Spans
      • 10.1.1 Fixed and Dynamic Extent
      • 10.1.2 Example Using a Span with Fixed Extent
      • 10.1.3 Example Using a Span with Dynamic Extent
    • 10.2 Spans Considered Harmful
    • 10.3 Design Aspects of Spans
      • 10.3.1 Performance of Spans
      • 10.3.2 const Correctness of Spans
      • 10.3.3 Using Spans as Parameters in Generic Code
    • 10.4 Span Operations
      • 10.4.1 Span Operations and Member Types Overview
    • 10.5 Afternotes
  • 11. Non-Type Template Parameter (NTTP) Extensions
    • 11.1 New Types for Non-Type Template Parameters
      • 11.1.1 double Values as Non-Type Template Parameters
      • 11.1.2 Objects as Non-Type Template Parameters
      • 11.1.3 Lambdas as Non-Type Template Parameters
    • 11.2 Details of Floating-Point Values as NTTP’s
    • 11.3 Details of Objects as NTTP’s
    • 11.4 Details of Lambdas as NTTP’s
    • 11.5 Afternotes
  • 12. Coroutines
    • 12.1 What are Coroutines?
    • 12.2 A First Coroutine Example
      • 12.2.1 Defining a Coroutine
    • 12.3 Further Coroutine Examples
      • 12.3.1 Coroutine with co_yield
      • 12.3.2 Coroutine with co_return
    • 12.4 Coroutines in Detail
    • 12.5 Afternotes
  • 13. Formatted Output
    • 13.1 Formatted Output by Example
      • 13.1.1 Using std::format()
      • 13.1.2 Using std::format_to_n()
      • 13.1.3 Using std::format_to()
      • 13.1.4 Using std::formatted_size()
    • 13.2 Formatted Output in Detail
    • 13.3 User-Defined Formatted Output
    • 13.4 Afternotes
  • 14. Dates and Time Zones for <chrono>
    • 14.1 Overview by Example
      • 14.1.1 Schedule a Meeting at the 5th of Every Month
      • 14.1.2 Schedule a Meeting Every First Monday
    • 14.2 Basic Chrono Concepts and Terminology
    • 14.3 Basic Chrono Extensions with C++20
      • 14.3.1 Duration Types
      • 14.3.2 Clocks
      • 14.3.3 Timepoint Types
      • 14.3.4 Calendrical Types
      • 14.3.5 Time Type hh_mm_ss
    • 14.4 Time Zones
      • 14.4.1 Characteristics of Time Zones
      • 14.4.2 Using Time Zones
    • 14.5 I/O with Chrono Types
      • 14.5.1 Default Output Formats
      • 14.5.2 Formatted Output
      • 14.5.3 Formatted Input
    • 14.6 Using the Chrono Extensions in Practice
      • 14.6.1 Invalid Dates
      • 14.6.2 Dealing with months and years
      • 14.6.3 Parsing Time Points and Durations
      • 14.6.4 Dealing with Time Zone Abbreviations
      • 14.6.5 Custom Timezones
    • 14.7 Clocks in Detail
      • 14.7.1 Clocks with a Specified Epoch
      • 14.7.2 The Pseudo Clock local_t
      • 14.7.3 Dealing with Leap Seconds
      • 14.7.4 Conversions between Clocks
      • 14.7.5 Dealing with the File Clock
    • 14.8 Other New Chrono Features
    • 14.9 Afternotes
  • 15. std::jthread and Stop Tokens
    • 15.1 Motivation for std::jthread
      • 15.1.1 The Problem of std::thread
      • 15.1.2 Using std::jthread
      • 15.1.3 Stop Tokens and Stop Callbacks
    • 15.2 Stop Sources and Stop Tokens
      • 15.2.1 Stop Sources and Stop Tokens in Detail
      • 15.2.2 Using Stop Callbacks
      • 15.2.3 Constraints and Guarantees of Stop Tokens
    • 15.3 std::jthread In Detail
      • 15.3.1 Using Stop Tokens with std::jthread
    • 15.4 Afternotes
  • 16. Concurrency Features
    • 16.1 Thread Synchronization with Latches and Barriers
      • 16.1.1 Latches
      • 16.1.2 Barriers
    • 16.2 Semaphores
      • 16.2.1 Example of Using Counting Semaphores
      • 16.2.2 Example of Using Binary Semaphores
    • 16.3 Extensions for and New Atomic Types
    • 16.4 Atomic References with std::atomic_ref<>
      • 16.4.1 Atomic Shared Pointers
      • 16.4.2 Atomic Floating-Point Types
      • 16.4.3 Thread Synchronization with Atomic Types
      • 16.4.4 Extensions for std::atomic_flag
    • 16.5 Afternotes
  • 17. Glossary
    • 17.1 A
      • 17.1.1 argument-dependent lookup (ADL)
    • 17.2 C
      • 17.2.1 class template argument deduction (CTAD)
    • 17.3 F
      • 17.3.1 full specialization
    • 17.4 G
      • 17.4.1 glvalue
    • 17.5 I
      • 17.5.1 incomplete type
    • 17.6 L
      • 17.6.1 lvalue
    • 17.7 P
      • 17.7.1 partial specialization
      • 17.7.2 predicate
      • 17.7.3 prvalue
    • 17.8 R
      • 17.8.1 resource acquisition is initialization (RAII)
      • 17.8.2 regular type
      • 17.8.3 rvalue
    • 17.9 S
      • 17.9.1 semiregular type
      • 17.9.2 substitution failure is not an error (SFINAE)
      • 17.9.3 small/short string optimization (SSO)
      • 17.9.4 stateless
      • 17.9.5 standard template library (STL)
    • 17.10 V
      • 17.10.1 value category
      • 17.10.2 variable template
      • 17.10.3 variadic template
    • 17.11 X
      • 17.11.1 xvalue
  • Notes

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

Do Well. Do Good.

Authors have earned$10,607,028writing, 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

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

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF, EPUB and/or MOBI files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub