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)

Easily find feature test macros with the <version> header

C++ has provided some form of feature test macros for as long as new features have been added. Beginning with C++20, the process is standardized, and all library feature test macros have been added to the <version> header. This will make it much easier to test for a new feature in your code.

This is a useful feature and it's very simple to use.

How to do it…

All feature test macros begin with the prefix __cpp_. Library features begin with __cpp_lib_. Language feature test macros are typically defined by the compiler. Library feature test macros are defined in the new <version> header. Use them as you would any other preprocessor macro:

#include <version>
#ifdef __cpp_lib_three_way_comparison
#   include <compare>
#else
#   error Spaceship has not yet landed
#endif

In some cases, you can use the __has_include preprocessor operator (introduced...