C++17 STL Cookbook

Over 90 recipes that leverage the powerful features of the Standard Library in C++17
Preview in Mapt

C++17 STL Cookbook

Jacek Galowicz

5 customer reviews
Over 90 recipes that leverage the powerful features of the Standard Library in C++17
Mapt Subscription
FREE
$29.99/m after trial
eBook
$28.00
RRP $39.99
Save 29%
Print + eBook
$49.99
RRP $49.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$28.00
$49.99
$29.99p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 30 Day Trial

Frequently bought together


C++17 STL Cookbook Book Cover
C++17 STL Cookbook
$ 39.99
$ 28.00
Mastering the C++17 STL Book Cover
Mastering the C++17 STL
$ 35.99
$ 25.20
Buy 2 for $35.00
Save $40.98
Add to Cart
Subscribe and access every Packt eBook & Video.
 
  • 5,000+ eBooks & Videos
  • 50+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 

Book Details

ISBN 139781787120495
Paperback532 pages

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.

Table of Contents

Chapter 1: The New C++17 Features
Introduction
Using structured bindings to unpack bundled return values
Limiting variable scopes to if and switch statements
Profiting from the new bracket initializer rules
Letting the constructor automatically deduce the resulting template class type
Simplifying compile time decisions with constexpr-if
Enabling header-only libraries with inline variables
Implementing handy helper functions with fold expressions
Chapter 2: STL Containers
Introduction
Using the erase-remove idiom on std::vector
Deleting items from an unsorted std::vector in O(1) time
Accessing std::vector instances the fast or the safe way
Keeping std::vector instances sorted
Inserting items efficiently and conditionally into std::map
Knowing the new insertion hint semantics of std::map::insert
Efficiently modifying the keys of std::map items
Using std::unordered_map with custom types
Filtering duplicates from user input and printing them in alphabetical order with std::set
Implementing a simple RPN calculator with std::stack
Implementing a word frequency counter with std::map
Implement a writing style helper tool for finding very long sentences in text with std::multimap
Implementing a personal to-do list using std::priority_queue
Chapter 3: Iterators
Introduction
Building your own iterable range
Making your own iterators compatible with STL iterator categories
Using iterator adapters to fill generic data structures
Implementing algorithms in terms of iterators
Iterating the other way around using reverse iterator adapters
Terminating iterations over ranges with iterator sentinels
Automatically checking iterator code with checked iterators
Building your own zip iterator adapter
Chapter 4: Lambda Expressions
Introduction
Defining functions on the run using lambda expressions
Adding polymorphy by wrapping lambdas into std::function
Composing functions by concatenation
Creating complex predicates with logical conjunction
Calling multiple functions with the same input
Implementing transform_if using std::accumulate and lambdas
Generating cartesian product pairs of any input at compile time
Chapter 5: STL Algorithm Basics
Introduction
Copying items from containers to other containers
Sorting containers
Removing specific items from containers
Transforming the contents of containers
Finding items in ordered and unordered vectors
Limiting the values of a vector to a specific numeric range with std::clamp
Locating patterns in strings with std::search and choosing the optimal implementation
Sampling large vectors
Generating permutations of input sequences
Implementing a dictionary merging tool
Chapter 6: Advanced Use of STL Algorithms
Introduction
Implementing a trie class using STL algorithms
Implementing a search input suggestion generator with tries
Implementing the Fourier transform formula with STL numeric algorithms
Calculating the error sum of two vectors
Implementing an ASCII Mandelbrot renderer
Building our own algorithm - split
Composing useful algorithms from standard algorithms - gather
Removing consecutive whitespace between words
Compressing and decompressing strings
Chapter 7: Strings, Stream Classes, and Regular Expressions
Introduction
Creating, concatenating, and transforming strings
Trimming whitespace from the beginning and end of strings
Getting the comfort of std::string without the cost of constructing std::string objects
Reading values from user input
Counting all words in a file
Formatting your output with I/O stream manipulators
Initializing complex objects from file input
Filling containers from std::istream iterators
Generic printing with std::ostream iterators
Redirecting output to files for specific code sections
Creating custom string classes by inheriting from std::char_traits
Tokenizing input with the regular expression library
Comfortably pretty printing numbers differently per context on the fly
Catching readable exceptions from std::iostream errors
Chapter 8: Utility Classes
Introduction
Converting between different time units using std::ratio
Converting between absolute and relative times with std::chrono
Safely signalizing failure with std::optional
Applying functions on tuples
Quickly composing data structures with std::tuple
Replacing void* with std::any for more type safety
Storing different types with std::variant
Automatically handling resources with std::unique_ptr
Automatically handling shared heap memory with std::shared_ptr
Dealing with weak pointers to shared objects
Simplifying resource handling of legacy APIs with smart pointers
Sharing different member values of the same object
Generating random numbers and choosing the right random number engine
Generating random numbers and letting the STL shape specific distributions
Chapter 9: Parallelism and Concurrency
Introduction
Automatically parallelizing code that uses standard algorithms
Putting a program to sleep for specific amounts of time
Starting and stopping threads
Performing exception safe shared locking with std::unique_lock and std::shared_lock
Avoiding deadlocks with std::scoped_lock
Synchronizing concurrent std::cout use
Safely postponing initialization with std::call_once
Pushing the execution of tasks into the background using std::async
Implementing the producer/consumer idiom with std::condition_variable
Implementing the multiple producers/consumers idiom with std::condition_variable
Parallelizing the ASCII Mandelbrot renderer using std::async
Implementing a tiny automatic parallelization library with std::future
Chapter 10: Filesystem
Introduction
Implementing a path normalizer
Getting canonical file paths from relative paths
Listing all files in directories
Implementing a grep-like text search tool
Implementing an automatic file renamer
Implementing a disk usage counter
Calculating statistics about file types
Implementing a tool that reduces folder size by substituting duplicates with symlinks

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 available with the C++17 STL

Authors

Table of Contents

Chapter 1: The New C++17 Features
Introduction
Using structured bindings to unpack bundled return values
Limiting variable scopes to if and switch statements
Profiting from the new bracket initializer rules
Letting the constructor automatically deduce the resulting template class type
Simplifying compile time decisions with constexpr-if
Enabling header-only libraries with inline variables
Implementing handy helper functions with fold expressions
Chapter 2: STL Containers
Introduction
Using the erase-remove idiom on std::vector
Deleting items from an unsorted std::vector in O(1) time
Accessing std::vector instances the fast or the safe way
Keeping std::vector instances sorted
Inserting items efficiently and conditionally into std::map
Knowing the new insertion hint semantics of std::map::insert
Efficiently modifying the keys of std::map items
Using std::unordered_map with custom types
Filtering duplicates from user input and printing them in alphabetical order with std::set
Implementing a simple RPN calculator with std::stack
Implementing a word frequency counter with std::map
Implement a writing style helper tool for finding very long sentences in text with std::multimap
Implementing a personal to-do list using std::priority_queue
Chapter 3: Iterators
Introduction
Building your own iterable range
Making your own iterators compatible with STL iterator categories
Using iterator adapters to fill generic data structures
Implementing algorithms in terms of iterators
Iterating the other way around using reverse iterator adapters
Terminating iterations over ranges with iterator sentinels
Automatically checking iterator code with checked iterators
Building your own zip iterator adapter
Chapter 4: Lambda Expressions
Introduction
Defining functions on the run using lambda expressions
Adding polymorphy by wrapping lambdas into std::function
Composing functions by concatenation
Creating complex predicates with logical conjunction
Calling multiple functions with the same input
Implementing transform_if using std::accumulate and lambdas
Generating cartesian product pairs of any input at compile time
Chapter 5: STL Algorithm Basics
Introduction
Copying items from containers to other containers
Sorting containers
Removing specific items from containers
Transforming the contents of containers
Finding items in ordered and unordered vectors
Limiting the values of a vector to a specific numeric range with std::clamp
Locating patterns in strings with std::search and choosing the optimal implementation
Sampling large vectors
Generating permutations of input sequences
Implementing a dictionary merging tool
Chapter 6: Advanced Use of STL Algorithms
Introduction
Implementing a trie class using STL algorithms
Implementing a search input suggestion generator with tries
Implementing the Fourier transform formula with STL numeric algorithms
Calculating the error sum of two vectors
Implementing an ASCII Mandelbrot renderer
Building our own algorithm - split
Composing useful algorithms from standard algorithms - gather
Removing consecutive whitespace between words
Compressing and decompressing strings
Chapter 7: Strings, Stream Classes, and Regular Expressions
Introduction
Creating, concatenating, and transforming strings
Trimming whitespace from the beginning and end of strings
Getting the comfort of std::string without the cost of constructing std::string objects
Reading values from user input
Counting all words in a file
Formatting your output with I/O stream manipulators
Initializing complex objects from file input
Filling containers from std::istream iterators
Generic printing with std::ostream iterators
Redirecting output to files for specific code sections
Creating custom string classes by inheriting from std::char_traits
Tokenizing input with the regular expression library
Comfortably pretty printing numbers differently per context on the fly
Catching readable exceptions from std::iostream errors
Chapter 8: Utility Classes
Introduction
Converting between different time units using std::ratio
Converting between absolute and relative times with std::chrono
Safely signalizing failure with std::optional
Applying functions on tuples
Quickly composing data structures with std::tuple
Replacing void* with std::any for more type safety
Storing different types with std::variant
Automatically handling resources with std::unique_ptr
Automatically handling shared heap memory with std::shared_ptr
Dealing with weak pointers to shared objects
Simplifying resource handling of legacy APIs with smart pointers
Sharing different member values of the same object
Generating random numbers and choosing the right random number engine
Generating random numbers and letting the STL shape specific distributions
Chapter 9: Parallelism and Concurrency
Introduction
Automatically parallelizing code that uses standard algorithms
Putting a program to sleep for specific amounts of time
Starting and stopping threads
Performing exception safe shared locking with std::unique_lock and std::shared_lock
Avoiding deadlocks with std::scoped_lock
Synchronizing concurrent std::cout use
Safely postponing initialization with std::call_once
Pushing the execution of tasks into the background using std::async
Implementing the producer/consumer idiom with std::condition_variable
Implementing the multiple producers/consumers idiom with std::condition_variable
Parallelizing the ASCII Mandelbrot renderer using std::async
Implementing a tiny automatic parallelization library with std::future
Chapter 10: Filesystem
Introduction
Implementing a path normalizer
Getting canonical file paths from relative paths
Listing all files in directories
Implementing a grep-like text search tool
Implementing an automatic file renamer
Implementing a disk usage counter
Calculating statistics about file types
Implementing a tool that reduces folder size by substituting duplicates with symlinks

Book Details

ISBN 139781787120495
Paperback532 pages
Read More
From 5 reviews

Read More Reviews

Recommended for You

Boost C++ Application Development Cookbook Book Cover
Boost C++ Application Development Cookbook
$ 29.99
$ 21.00
Mastering Python Book Cover
Mastering Python
$ 31.99
$ 22.40
Learning Boost C++ Libraries Book Cover
Learning Boost C++ Libraries
$ 39.99
$ 28.00
C++ Multithreading Cookbook Book Cover
C++ Multithreading Cookbook
$ 29.99
$ 21.00
Python Machine Learning Book Cover
Python Machine Learning
$ 35.99
$ 25.20
Compass - powerful SASS library that makes your life easier [Video] Book Cover
Compass - powerful SASS library that makes your life easier [Video]
$ 53.99
$ 45.90