Skip to main content
main-content
Top

About this book

This quick reference is a condensed guide to the essential data structures, algorithms, and functions provided by the C++ Standard Library. Used by millions of C++ programmers on a daily basis, the C++ Standard Library features core classes for strings, I/O streams, and various generic containers, as well as a comprehensive set of algorithms to manipulate them. In recent years, the C++11 and C++14 standards have added even more efficient container classes, a new powerful regular expression library, and a portable multithreading library featuring threads, mutexes, condition variables, and atomic variables.

Needless to say, it is hard to know and remember all the possibilities, details, and intricacies of this vast and growing library. This handy reference guide is therefore indispensable to any C++ programmer. It offers a condensed, well-structured summary of all essential aspects of the C++ Standard Library. No page-long, repetitive examples or obscure, rarely used features. Instead, everything you need to know and watch out for in practice is outlined in a compact, to-the-point style, interspersed with practical tips and well-chosen, clarifying examples. The book does not explain the C++ language or syntax, but is accessible to anyone with basic C++ knowledge or programming experience. Even the most experienced C++ programmer though will learn a thing or two from it and find it a useful memory-aid. Among the topics covered are:

What You Will LearnGain the essentials that the C++ Standard Library has to offer

Use containers to efficiently store and retrieve your data

Use algorithms to inspect and manipulate your data

See how lambda expressions allow for elegant use of algorithms

Discover what the standard string class provides and how to use it

Write localized applications

Work with file and stream-based I/O

Discover what smart pointers are and how to use them to prevent memory leaks

Write safe and efficient multi-threaded code using the threading libraries

Who This Book Is For

All C++ programmers: irrespective of their proficiency with the language or the Standard Library, this book offers an indispensable reference and memory-aid.

A secondary audience is developers who are new to C++, but not new to programming, and who want to learn more on the C++ Standard Library in a quick, condensed manner.

Table of Contents

Chapter 1. Numerics and Math

Abstract
The <cmath> header Mathematical functions defines an extensive collection of common math functions in the std namespace. Unless otherwise specified, all functions are overloaded to accept all standard numerical types, with the following rules for determining the return type.
Peter Van Weert, Marc Gregoire

Chapter 2. General Utilities

Abstract
This section explains the functions move(), move_if_noexcept(), forward(), swap(), and exchange(). In passing, it also introduces the concepts of move semantics and perfect forwarding.
Peter Van Weert, Marc Gregoire

Chapter 3. Containers

Abstract
The C++ Standard Library provides a selection of different data structures that you can use to store data. Containers work in tandem with algorithms, described in Chapter 4. Containers and algorithms are designed in such a way that they do not need to know about each other. The interaction between them is accomplished with iterators. All containers provide iterators, and algorithms only need iterators to be able to perform their work.
Peter Van Weert, Marc Gregoire

Chapter 4. Algorithms

Abstract
The previous chapter discusses the containers provided by the Standard Library to store data. Orthogonally to these, the library offers numerous algorithms to process this or other data. Algorithms are independent of containers: they do their work solely based on iterators and can therefore be executed on any range of elements as long as suitable iterators are provided.
Peter Van Weert, Marc Gregoire

Chapter 5. Stream I/O

Abstract
The C++ stream-based I/O library allows you to perform I/O operations without having to know details about the target to or source from which you are streaming. A stream’s target or source could be a string, a file, a memory buffer, and so on.
Peter Van Weert, Marc Gregoire

Chapter 6. Characters and Strings

Abstract
The Standard defines four different string types, each for a different char-like type.
Peter Van Weert, Marc Gregoire

Chapter 7. Concurrency

Abstract
To run any function pointer, functor, or lambda expression in a new thread of execution, pass it to the constructor of std::thread, along with any number of arguments. For example, these two lines are equivalent.
Peter Van Weert, Marc Gregoire

Chapter 8. Diagnostics

Abstract
Assertions are Boolean expressions that are expected to be true at a given point in the code. The assert macro of <cassert> is defined similar to this.
Peter Van Weert, Marc Gregoire
Additional information