Getting Started with C++20/23

Getting Started with C++20/23 is a two-day onsite training course with programming examples, taught by Jeff Garland.  It is offered at the Gaylord Rockies from 09:00 to 17:00 Aurora time (MDT) on Saturday and Sunday, September 17th and 18th, 2022 (immediately following the conference). Lunch is included.

Course Description

C++20 is a huge release with many new features to learn making it daunting to get started. While C++23 is a smaller release, it adds many new library features. This tutorial will do a deep dive on concepts, ranges, span, format, chrono, jthread, and other key C++20/23 library facilities from an application developer’s perspective. A combination of lecture and hands-on exercises provides the student a hands-on working knowledge of the best of C++20/23. Targeted at intermediate to advanced developers this session expects no prior knowledge of C++20/23. The session focuses on facilities that are immediately available and shipping in C++ compilers.

Day 1 is devoted to concepts. Over the course of the day we will climb up the ladder from the basics of concepts to writing and designing with concepts. First we cover the basics of concepts, the concept and requires keywords. Then we explore the application of concepts from a library user point of view. Including as a variable declaration, return values, and function parameters. Then we’ll survey and apply C++20 standard library concepts to typical development of a typical C++ class. Next the tutorial will dig into writing concepts including what makes a good concept. We will look at the details of how concepts are evaluated. Finally, we’ll tie our new knowledge and look at some ways concepts can impact C++ designs including CRTP and SOLID.

Day 2 is devoted to the new standard library facilities and how best to use them. Ranges algorithms, adapters, and views get a deep treatment. As part of an exercise we build custom view adapters so students can extend ranges for their own applications. Next we look at using span and how it can simplify and improve interfaces. Using the spaceship operator and the provided standard library support in building types is next. With format we look at the new facilities, the basics of use and how developers can extend the facilities to work well with their own types. For chrono we see the new API for working with dates and times including format for input and output. Finally, we wrap up with some smaller facilities that solve everyday issues like container erase algorithms and signed/unsigned comparison facilities.


Students are expected to have basic C++ familiarity. Some template programming experience is useful.

Course Topics

Day 1: Concepts

  • Introduction
  • Concept basics
    • Why do we want concepts?
    • Why do we want concepts II?
    • Long history
    • What’s a concept?
    • Boolean predicate composition
    • Types versus concepts
    • Simple one parameter concept printable
    • Notable concept properties
  • Using concepts in code
    • What can we do/not do with a concept?
    • Where can we write <concept_name> auto ?
    • Overload resolution – constrain function parameter
    • Pointers and concepts
    • Use in if constexpr
    • Non-template member function of template class
    • Constraining existing templates
    • Using standard library concepts
  • Writing concepts
    • How constraints are evaluated
    • Good concepts and bad concepts
    • Evolving concepts
    • Concepts for sleep_for
    • Refactoring the sleep_for concept
  • Designing with concepts
    • What is design?
    • Parnas – information hiding (1972)
    • Coplien – multi-paradigm design (1999)
    • Concept serialization
  • Conclusions & resources
    • Is concepts everything we want?
    • Final thoughts
    • Papers, blogs, videos

Day 2 : C++20 and C++23 Library Features

  • Range basics
    • Range, range algorithms, views, adaptors
    • Mechanics – headers, namespaces
    • Why put this in std::ranges instead of just std
    • What’s a range?
    • Range algorithms
    • Views are ranges with ‘lazy evaluation’
    • Range adaptors -> views from ranges
    • Views and range algorithm example
    • Collections != views, but are ranges
    • No more for loops – for real?
  • Range algorithms details and survey
    • The range algorithms are familiar
    • Projection parameters
    • Algorithms cheat sheet
    • Exercise: range algorithm with projection parameters
  • Range views and view adaptor details
    • Range adaptor equivalence
    • Types in a view chain – under the hood
    • View types
  • Survey of views – by example
    • iota_view example
    • take_view example
    • join_view char string example
    • empty_view example
    • single_view example
    • split_view char string example
    • reverse_view example 2
    • transform_view example
    • drop_while example
    • Cheat sheet
    • Exercise: composing several views
  • Making a custom view
    • View interface design details
    • Avoiding the boilerplate
    • Exercise: make a custom view type
  • span
    • Span construction
    • Span for better function interfaces
    • span and const
    • Basic public accessors
    • Static and dynamic extent
    • spanstream (C++23)
    • Exercise: using span with vector and ranges
  • Spaceship operator <=>
    • It’s not rocket science, but…
    • Comparison is harder than you think
    • Expression rewriting
    • Move over less, it’s all about equal now
    • Simplifying your code with spaceship
  • Output with std::format
    • Hello world
    • Indexed parameters
    • Simple escaping
    • Crazy town
    • Format specifiers
    • Rich language for fill, alignment, conversion
    • Floating point format
    • Locale support
    • Custom type usage
    • How to extend for custom type
    • fmt diagnostics/safety
    • Mis-matched parameter count
    • Wrong format typing causes error, even when convertible
    • format exercise – references and status
  • Chrono
    • Chrono design fundamentals
    • Simple calculations
    • Chrono error handling
    • Other types year_month, gps_clock, weekday_indexed
    • Chrono i/o
    • Chrono format output
    • Locale aware format output
    • IANA timezone database support
    • Localized times
    • Other C++20 chrono features
    • Chrono exercise – references and status
  • Concurrency: threading and atomics
    • jthread and stop_token
    • Atomic shared_ptr and weak_ptr
    • atomic_ref
    • syncbuf and osyncstream overview
  • Misc smaller things
    • uniform container erasure
    • Safe signed and unsigned comparison
    • contains method for associative containers
    • source_location
    • starts_with and ends_with for string and string_view
    • Math constants
    • stringstream and basic_stringbuf updates

Register Here

Course Instructor

Jeff Garland is the assistant chair of the WG21 Library Working Group, a Boost author, and a recurring conference speaker. He has been writing high performance, distributed C++ applications since the late 90’s in domains ranging from financial systems to satellite ground control. He holds a Masters in Computer Science from ASU and a Bachelor of Science in Systems Engineering from the University of Arizona.

Jeff is a software architect, principal engineer, and security champion with more than 15 years of experience in designing, writing and maintaining C++ code for fun and living. C++ consultant, trainer, conference speaker, and evangelist focused on Modern C++. His main areas of interest and expertise are code performance, low latency, stability, and security.