Modern C++ Programming Cookbook – Third Edition

The Third Edition of my book, Modern C++ Programming Cookbook (ISBN 978-1835080542) has been published by Packt. The book can be ordered from Amazon and Packt.

The book is organized in recipes, much like a cookbook. These recipes, in turn, are organized in sections that introduce you to the topic, list any necessary pre-requisites and then explain how to do something and how that works. This second edition comes with more than 150 recipes covering language and library features from C++11/14/17/20/23, including the libraries for strings, containers, algorithms, iterators, input/output, regular expressions, threads, filesystem, date and time, atomic operations, and utilities. Besides that, there is a chapter for patterns and idioms and one dedicated for testing frameworks, that covers everything you need to know to get started with Boost.Test, Google Test and Catch2. There is also a entire new chapter for the C++20 major features: modules, concepts, coroutines, and ranges.

This third edition, is an update that covers the new C++23 standard, but includes other topics too. There are 23 new recipes and as many updated ones. The C++23 features discussed in the book include:

  • stacktrace library
  • std::expected
  • std::mdspan
  • std::optional monadic operations
  • span buffers
  • if consteval
  • range adaptors
  • std::generator
  • multidimensional subscript operator
  • std::to_underlying() and std::is_scoped_enum
  • std::print() and std::println()
  • #warning, #elifdef, #elifndef
  • [[assume]] attribute
  • static constexpr variables

Apart from these, there are also new recipes on C++20 topics not covered before:

  • std::source_location
  • sync streams (std::osyncstream)
  • constexpr virtual functions
  • cmp_ functions (std::cmp_equal, cmp_not_equal, cmp_less, cmp_greater, cmp_less_equal, cmp_greater_equal)
  • abbreviated function templates

But this is not all, there are more changes, including:

  • usage examples for all range adaptors
  • more patterns/idioms: mixins and type erasure
  • tips for selecting the right standard container
  • character and string types
  • fixed examples for features that were changed after publishing the 2nd edition, such as chrono library types, text formatting library, and coroutines

Overall, the Third Edition is a significant update of the book. It is intended to help you learn what’s new in C++23, but not only.

All the code snippets from the book, are available in this Github repo.

I hope you will enjoy the book and find it helpful for learning new things about C++. Your feedback/review of the book is always welcomed.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.