Book Image

C++20 STL Cookbook

By : Bill Weinman
Book Image

C++20 STL Cookbook

By: Bill Weinman

Overview of this book

Fast, efficient, and flexible, the C++ programming language has come a long way and is used in every area of the industry to solve many problems. The latest version C++20 will see programmers change the way they code as it brings a whole array of features enabling the quick deployment of applications. This book will get you up and running with using the STL in the best way possible. Beginning with new language features in C++20, this book will help you understand the language's mechanics and library features and offer insights into how they work. Unlike other books, the C++20 STL Cookbook takes an implementation-specific, problem-solution approach that will help you overcome hurdles quickly. You'll learn core STL concepts, such as containers, algorithms, utility classes, lambda expressions, iterators, and more, while working on real-world recipes. This book is a reference guide for using the C++ STL with its latest capabilities and exploring the cutting-edge features in functional programming and lambda expressions. By the end of the book C++20 book, you'll be able to leverage the latest C++ features and save time and effort while solving tasks elegantly using the STL.
Table of Contents (13 chapters)

What this book covers

Chaper 1, New C++20 Features, introduces the new STL features in C++20. It aims to familiarize you with the new language features so you may use them with the STL.

Chapter 2, General STL Features, discusses modern STL features added in recent C++ versions.

Chapter 3, STL Containers, covers the STL's comprehensive library of containers.

Chapter 4, Compatible Iterators, shows how to use and create STL-compatible iterators.

Chapter 5, Lambda Expressions, covers the use of lambdas with STL functions and algorithms.

Chapter 6, STL Algorithms, provides recipes for using and creating STL-compatible algorithms.

Chapter 7, Strings, Stream, and Formatting, describes the STL string and formatter classes.

Chapter 8, Utility Classes, covers STL utilities for date-and-time, smart pointers, optionals, and more.

Chapter 9, Concurrency and Parallelism, describes support for concurrency, including threads, async, atomic types, and more.

Chapter 10, Using the File System, covers the std::filesystem classes and how to put them to use with the latest advancements that came out with C++20.

Chapter 11, A Few More Ideas, provides a few more solutions, including a trie class, string split, and more. This provides advanced examples on how to put the STL to use for real-world problems.

The recipes in this book use the GCC compiler

Unless otherwise noted, most of the recipes in this book have been developed and tested using the GCC compiler, version 11.2, the latest stable version as of this writing.

As I write this, C++20 is still new and is not fully implemented on any available compiler. Of the three major compilers, GCC (GNU), MSVC (Microsoft), and Clang (Apple), the MSVC compiler is furthest along in implementing the new standard. Occasionally, we may run into a feature that is implemented on MSVC or another compiler, but not on GCC, in which case I will note which compiler I used. If a feature is not yet implemented on any available compiler, I will explain that I was unable to test it.

I strongly recommend that you install GCC to follow along with the recipes in this book. GCC is freely available under the GNU General Public License (GPL). The easiest way to get the latest version of GCC is to install Debian Linux (also GPL) and use apt with the testing repository.

If you are using the digital version of this book, we suggest you type the code yourself or download the code from the GitHub repository (link in the next section). This will avoid errors due to copying and pasting formatted code from the e-book.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/CPP-20-STL-Cookbook. In the event of updates and errata, code will be updated on the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!