Share E-Book
Scan to open this page

Scan with your phone to open this page

AuthorJacek Galowicz

Key Features • Learn the latest features of C++ and how to write better code by using the Standard Library (STL). Reduce the development time for your applications. • Understand the scope and power of STL features to deal with real-world problems. • Compose your own algorithms without forfeiting the simplicity and elegance of the STL way. Book Description C++ has come a long way and is in use in every area of the industry. Fast, efficient, and flexible, it is used to solve many problems. The upcoming version of C++ will see programmers change the way they code. If you want to grasp the practical usefulness of the C++17 STL in order to write smarter, fully portable code, then this book is for you. Beginning with new language features, this book will help you understand the language's mechanics and library features, and offers insight into how they work. Unlike other books, ours takes an implementation-specific, problem-solution approach that will help you quickly overcome hurdles. You will learn the core STL concepts, such as containers, algorithms, utility classes, lambda expressions, iterators, and more, while working on practical real-world recipes. These recipes will help you get the most from the STL and show you how to program in a better way. By the end of the book, you will be up to date with the latest C++17 features and save time and effort while solving tasks elegantly using the STL. What you will learn • Learn about the new core language features and the problems they were intended to solve • Understand the inner workings and requirements of iterators by implementing them • Explore algorithms, functional programming style, and lambda expressions • Leverage the rich, portable, fast, and well-tested set of well-designed algorithms provided in the STL • Work with strings the STL way instead of handcrafting C-style code • Understand standard support classes for concurrency and synchronization, and how to put them to work • Use the filesystem library addition

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# C++17 STL Cookbook — Reading Guide ## 【One-Line Pitch】 A practical, recipe-driven tour of C++17's Standard Library that shows you how to solve real-world problems with modern, elegant, and portable code — ideal for intermediate C++ developers who want to move beyond the basics and write idiomatic STL-style programs. ## 【Book Arc】 - **Opening (~0%–9%)**: Introduces the new C++17 core language features — `if`/`switch` with initializers, `constexpr-if`, and fold expressions — explaining the problems they solve (scope pollution, compile-time branching, variadic template expansion) and why they make metaprogramming more readable. - **Early (~16%–28%)**: Dives into STL containers — `std::vector`, `std::map`, `std::set`, `std::stack` — with recipes for keeping vectors sorted, handling out-of-bounds access safely, using insertion hints for performance, and building a reverse Polish notation calculator and sentence-length statistics tool. - **Early-to-Middle (~28%–38%)**: Explores iterators in depth — input/output iterators, reverse iterators, and `std::istream_iterator` — plus how to build custom iterator adapters like a "zip" iterator, with a strong emphasis on using sanitizers for bug detection. - **Middle (~38%–47%)**: Focuses on lambda expressions and functional programming style — capturing variables, composing functions with `std::function`, building multicall helpers, and generating cartesian products at compile time using parameter packs and lambdas. - **Late (~47%–end)**: Continues with advanced STL usage — algorithm composition, performance optimization, and practical patterns for combining the library's building blocks into clean, maintainable solutions (excerpts thin here; later chapters likely cover strings, concurrency, and filesystem). ## 【Key Takeaways】 - **C++17 language features reduce boilerplate and scope pollution** (Early): `if`/`switch` initializers keep variables scoped to the branch where they're used, making code tidier and easier to refactor — no more extra braces or leaked variables. - **`constexpr-if` revolutionizes template metaprogramming** (Early): Compile-time branching with `if constexpr` lets you write type-dependent code that reads like normal control flow, eliminating the need for complex SFINAE or tag dispatch in many cases. - **Fold expressions simplify variadic template operations** (Early): A single expression like `(std::count(std::begin(range), std::end(range), ts) + ...)` can replace pages of recursive template code — powerful for building concise, readable helpers. - **Containers have hidden performance tricks** (Early): `std::map` insertion hints can give amortized O(1) insertion when keys are neighbors, and keeping a `std::vector` sorted manually is often simpler than switching to a tree-based structure. - **Iterators are the backbone of STL algorithms** (Early): Understanding iterator categories (input, output, bidirectional, etc.) is essential — and `std::make_reverse_iterator` lets you reuse normal algorithms on reversed ranges with minimal effort. - **Lambdas enable powerful function composition** (Middle): Combining lambdas with `std::function` and parameter packs lets you build composable, Lego-brick-style utilities (like `multicall` or `transform_if`) that compile to efficient code with zero runtime overhead. - **Sanitizers are a professional necessity** (Middle): The author strongly advocates for regular testing with sanitizers — a practical habit that catches sneaky bugs and is often missing in real-world teams. ## 【Reading Tips】 - **Skim the opening language-feature chapters** (~0%–9%) if you're already familiar with C++17 basics — but do read the `constexpr-if` and fold-expression recipes carefully, as they're used throughout the rest of the book. - **Deep-read the container chapters** (~16%–28%): The recipes here (sorted vectors, insertion hints, RPN calculator) are the most transferable to daily work — pay attention to the "How it works" sections that explain the underlying data structures. - **Treat the iterator chapter** (~28%–38%) as essential foundation: The custom zip iterator recipe is challenging but worth the effort — it teaches you how iterators really work under the hood. - **Don't skip the lambda composition recipes** (~38%–47%): Even if you think you know lambdas, the multicall and cartesian-product examples show advanced patterns you won't find in most tutorials. - **Keep a compiler handy**: This is a hands-on cookbook — the recipes are meant to be typed, compiled, and experimented with, not just read. ## 【Coverage Limits】 This guide covers the first ~47% of the book in detail (language features, containers, iterators, lambdas). The later chapters on strings, algorithms, concurrency, and the filesystem library are not covered in the available excerpts. ##
Excerpt 1
-tested set of well-designed algorithms provided in the STL • Work with strings the STL way instead of handcrafting C-style code • Understand standard suppor...
View in text
Excerpt 2
to know, that before C++11, insertion hints were considered correct when they pointed before the position of the newly inserted item. There's more... Interes...
View in text
Excerpt 3
pointed to has been invalidated during the incrementation. This means that it is not possible to iterate over such a range multiple times. The std::istream_i...
View in text
Excerpt 4
er and just prints a line break character: int main() { auto f (brace_print('(', ')')); auto g (brace_print('[', ']')); auto h (brace_print('{', '}')); auto...
View in text
Excerpt 5
string is, of course, an iterable range (of characters) too. On the other hand, finding a string in a string means finding a range in another range. And this...
View in text
Excerpt 6
ng by converting all its letters to upper case, for example. The C library function toupper, which maps lower-case characters to upper-case characters and le...
View in text
Excerpt 7
file. Feeding a default-constructed file stream buffer into the cout stream buffer leads to cout being kind of deactivated. It will just drop its input we gi...
View in text
Excerpt 8
erally very simple and convenient. If we want to attach the notion of possible failure or optionality to any type T, we can just wrap it into std::optional<T...
View in text
Tags
AI categories
C++Programming LanguageCode
ISBN: 178712049X
Publisher: Packt Publishing
Publish Year: 2017
Language: English
Pages: 523
File Format: PDF
File Size: 9.1 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…