Book description
This book breaks down the C++ STL, teaching you how to extract its gems and apply them to your programming.
About This Book
- Boost your productivity as a C++ developer with the latest features of C++17
- Develop high-quality, fast, and portable applications with the varied features of the STL
- Migrate from older versions (C++11, C++14) to C++17
Who This Book Is For
This book is for developers who would like to master the C++ STL and make full use of its components. Prior C++ knowledge is assumed.
What You Will Learn
- Make your own iterator types, allocators, and thread pools.
- Master every standard container and every standard algorithm.
- Improve your code by replacing new/delete with smart pointers.
- Understand the difference between monomorphic algorithms, polymorphic algorithms, and generic algorithms.
- Learn the meaning and applications of vocabulary type, product type and sum type.
In Detail
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.
Style and approach
This book takes a concise but comprehensive approach to explaining and applying the C++ STL, one feature at a time.
Table of contents
- Preface
- Classical Polymorphism and Generic Programming
- Iterators and Ranges
-
The Iterator-Pair Algorithms
- A note about headers
- Read-only range algorithms
- Shunting data with std::copy
- Variations on a theme - std::move and std::move_iterator
- Complicated copying with std::transform
- Write-only range algorithms
- Algorithms that affect object lifetime
- Our first permutative algorithm: std::sort
- Swapping, reversing, and partitioning
- Rotation and permutation
- Heaps and heapsort
- Merges and mergesort
- Searching and inserting in a sorted array with std::lower_bound
- Deleting from a sorted array with std::remove_if
- Summary
-
The Container Zoo
- The notion of ownership
- The simplest container: std::array<T, N>
- The workhorse: std::vector<T>
- The speedy hybrid: std::deque<T>
- A particular set of skills: std::list<T>
- Roughing it with std::forward_list<T>
- Abstracting with std::stack<T> and std::queue<T>
- The useful adaptor: std::priority_queue<T>
- The trees: std::set<T> and std::map<K, V>
- Oddballs: std::multiset<T> and std::multimap<K, V>
- The hashes: std::unordered_set<T> and std::unordered_map<K, V>
- Where does the memory come from?
- Summary
-
Vocabulary Types
- The story of std::string
- Tagging reference types with reference_wrapper
- C++11 and algebraic types
- Working with std::tuple
- Expressing alternatives with std::variant
- Delaying initialization with std::optional
- Revisiting variant
- Infinite alternatives with std::any
- Type erasure in a nutshell
- Again with the type erasure: std::function
- Summary
- Smart Pointers
-
Concurrency
- The problem with volatile
- Using std::atomic<T> for thread-safe accesses
- Taking turns with std::mutex
- Always associate a mutex with its controlled data
- Special-purpose mutex types
- Waiting for a condition
- Promises about futures
- Packaging up tasks for later
- The future of futures
- Speaking of threads...
- Thread exhaustion and std::async
- Building your own thread pool
- Summary
-
Allocators
- An allocator is a handle to a memory resource
- Defining a heap with memory_resource
- Using the standard memory resources
- The 500 hats of the standard allocator
- Sticking a container to a single memory resource
- Using the standard allocator types
- Making a container allocator-aware
- Propagating downwards with scoped_allocator_adaptor
- Summary
- Iostreams
- Regular Expressions
- Random Numbers
- Filesystem
Product information
- Title: Mastering the C++17 STL
- Author(s):
- Release date: September 2017
- Publisher(s): Packt Publishing
- ISBN: 9781787126824
You might also like
book
C++20 STL Cookbook
Proven techniques to improve the efficiency of your programs using the Standard Template Library (STL) Key …
video
Complete Modern C++ (C++11/14/17)
This course provides an extensive exploration of C++. The journey starts with mastering the syntax and …
book
C++ Software Design
Good software design is essential for the success of your project, but designing software is hard …
book
Effective Modern C++
Coming to grips with C++11 and C++14 is more than a matter of familiarizing yourself with …