Book Image

Mastering the C++17 STL

By : Arthur O'Dwyer
Book Image

Mastering the C++17 STL

By: Arthur O'Dwyer

Overview of this book

Modern C++ has come a long way since 2011. The latest update, C++17, has just been ratified and several implementations are on the way. This book is your guide to the C++ standard library, including the very latest C++17 features. The book starts by exploring the C++ Standard Template Library in depth. You will learn the key differences between classical polymorphism and generic programming, the foundation of the STL. You will also learn how to use the various algorithms and containers in the STL to suit your programming needs. The next module delves into the tools of modern C++. Here you will learn about algebraic types such as std::optional, vocabulary types such as std::function, smart pointers, and synchronization primitives such as std::atomic and std::mutex. In the final module, you will learn about C++'s support for regular expressions and file I/O. By the end of the book you will be proficient in using the C++17 standard library to implement real programs, and you'll have gained a solid understanding of the library's own internals.
Table of Contents (13 chapters)

Summary

Regular expressions (regexes) are a good way to lex out the pieces of an input string before parsing them. The default regex dialect in C++ is the same as in JavaScript. Use this to your advantage.

Prefer to avoid raw string literals in situations where an extra pair of parentheses could be confusing. When possible, limit the number of escaped backslashes in your regexes by using square brackets to escape special characters instead.

std::regex rx is basically immutable and represents a finite state machine. std::smatch m is mutable and holds information about a particular match within the haystack string. Submatch m[0] represents the whole matched substring; m[k] represents the kth capturing group.

std::regex_match(s, m, rx) matches the needle against the entire haystack string; std::regex_search(s, m, rx) looks for the needle in the haystack. Remember that the haystack...