C++20 STL Cookbook - Bill Weinman - E-Book

C++20 STL Cookbook E-Book

Bill Weinman

0,0
33,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Fast, efficient, and flexible, the C++ programming language has come a long way and is used in every area of the industry to solve many problems. The latest version C++20 will see programmers change the way they code as it brings a whole array of features enabling the quick deployment of applications. This book will get you up and running with using the STL in the best way possible.
Beginning with new language features in C++20, this book will help you understand the language's mechanics and library features and offer insights into how they work. Unlike other books, the C++20 STL Cookbook takes an implementation-specific, problem-solution approach that will help you overcome hurdles quickly. You'll learn core STL concepts, such as containers, algorithms, utility classes, lambda expressions, iterators, and more, while working on real-world recipes. This book is a reference guide for using the C++ STL with its latest capabilities and exploring the cutting-edge features in functional programming and lambda expressions.
By the end of the book C++20 book, you'll be able to leverage the latest C++ features and save time and effort while solving tasks elegantly using the STL.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 428

Veröffentlichungsjahr: 2022

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



C++20 STL Cookbook

Leverage the latest features of the STL to solve real-world problems

Bill Weinman

BIRMINGHAM—MUMBAI

C++20 STL Cookbook

Copyright © 2022 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Richa Tripathi

Publishing Product Manager: Gebin George

Senior Editor: Rohit Singh

Technical Editor: Pradeep Sahu

Copy Editor: Safis Editing

Project Coordinator: Manisha Singh

Proofreader: Safis Editing

Indexer: Manju Arasan

Production Designer: Ponraj Dhandapani

Marketing Coordinators: Pooja Yadav and Sonakshi Bubbar

First published: May 2022

Production reference: 1130522

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80324-871-4

www.packt.com

Contributors

About the author

Bill Weinman has been involved in technology since he built his first computer at age 16, in 1971. He's been coding in C and C++ since the early 1970s. He's written systems and applications for major clients, including NASA, Bank of America, Xerox, IBM, and the US Navy. Also an electronics engineer, he previously worked on the Voyager II spacecraft, audio amplifiers for SAE, and sound systems for Altec Lansing.

Since the mid 1990s, Mr. Weinman has focused on writing and teaching. His books and courses cover HTML, SQL, CGI, Python, and, of course, C and C++. An early contributor to online learning, his clear, concise writing has made his courses a popular feature on lynda.com and LinkedIn Learning.

Follow Bill on his website at bw.org.

About the reviewer

Vitalijs Vaznais was born in Daugavpils, Latvia. His favorite programming languages are C and C++, which he has been using for the last 26 years (and commercially for 24 years). He is pleased with the latest changes/evolution in both these languages and looks forward to seeing how they start to evolve.

Table of Contents

Preface

Chaper 1: New C++20 Features

Technical requirements

Format text with the new format library

How to do it…

How it works…

There's more…

Use compile-time vectors and strings with constexpr

How to do it…

How it works…

Safely compare integers of different types

How to do it…

How it works…

Use the "spaceship" operator <=> for three-way comparisons

How to do it…

How it works…

There's more…

Easily find feature test macros with the <version> header

How to do it…

How it works…

Create safer templates with concepts and constraints

How to do it…

How it works…

There's more…

Avoid re-compiling template libraries with modules

How to do it…

How it works…

Create views into containers with ranges

How to do it…

How it works…

There's more…

Chapter 2: General STL Features

Technical requirements

Use the new span class to make your C-arrays safer

How to do it…

How it works…

Use structured binding to return multiple values

How to do it…

How it works…

Initialize variables within if and switch statements

How to do it…

How it works…

There's more…

Use template argument deduction for simplicity and clarity

How to do it…

How it works…

There's more…

Use if constexpr to simplify compile-time decisions

How to do it…

How it works…

Chapter 3: STL Containers

A quick overview of the STL container types

Sequential containers

Associative containers

Container adapters

Technical requirements

Use uniform erasure functions to delete items from a container

How to do it…

How it works…

Delete items from an unsorted vector in constant time

How to do it…

How it works…

Access vector elements directly and safely

How to do it…

How it works…

There's more…

Keep vector elements sorted

How to do it…

How it works…

There's more…

Efficiently insert elements into a map

How to do it…

How it works…

Efficiently modify the keys of map items

How to do it…

How it works…

There's more…

Use unordered_map with custom keys

How to do it…

How it works…

Use set to sort and filter user input

How to do it…

How it works…

A simple RPN calculator with deque

How to do it…

How it works…

There's more…

A word frequency counter with map

How to do it…

How it works…

Find long sentences with a vector of vectors

How to do it…

How it works…

A ToDo list using multimap

How to do it…

How it works…

Chapter 4: Compatible Iterators

Iterators are fundamental

Iterator categories

Iterator concepts

Technical requirements

Create an iterable range

How to do it…

How it works…

There's more…

Make your iterators compatible with STL iterator traits

How to do it…

How it works…

There's more…

Use iterator adapters to fill STL containers

How to do it…

How it works…

Create a generator as iterators

How to do it…

How it works…

There's more…

Use reverse iterator adapters to iterate backward

How to do it…

How it works…

Iterate objects of unknown length with a sentinel

How to do it…

How it works…

Build a zip iterator adapter

How to do it…

How it works…

There's more…

Create a random-access iterator

How to do it…

How it works…

Chapter 5: Lambda Expressions

Lambda expressions

Closures

Technical requirements

Use lambdas for scoped reusable code

How to do it…

How it works…

Use lambdas as predicates with the algorithm library

How to do it…

How it works…

Use std::function as a polymorphic wrapper

How to do it…

How it works…

There's more…

Concatenate lambdas with recursion

How to do it…

How it works…

Combine predicates with logical conjunction

How to do it…

How it works…

Call multiple lambdas with the same input

How to do it…

How it works…

Use mapped lambdas for a jump table

How to do it…

How it works…

Chapter 6: STL Algorithms

Technical requirements

Copy from one iterator to another

How to do it…

How it works…

Join container elements into a string

How to do it…

How it works…

There's more…

Sort containers with std::sort

How to do it…

How it works…

Modify containers with std::transform

How to do it…

How it works…

Find items in a container

How to do it…

How it works…

There's more…

Limit the values of a container to a range with std::clamp

How to do it…

How it works…

Sample data sets with std::sample

How to do it…

How it works…

Generate permutations of data sequences

How to do it…

How it works…

Merge sorted containers

How to do it…

How it works…

Chapter 7: Strings, Streams, and Formatting

String formatting

Technical requirements

Use string_view as a lightweight string object

How to do it…

How it works…

Concatenate strings

How to do it…

How it works…

There's more…

Why would I choose one over another?

Transform strings

How to do it…

How it works…

Format text with C++20's format library

How to do it…

How it works…

There's more…

Trim whitespace from strings

How to do it…

How it works…

Read strings from user input

How to do it…

How it works…

Count words in a file

How to do it…

How it works…

Initialize complex structures from file input

How to do it…

How it works…

There's more…

Customize a string class with char_traits

How to do it…

How it works…

There's more…

Parse strings with Regular Expressions

How to do it…

How it works…

Chapter 8: Utility Classes

Technical requirements

Manage optional values with std::optional

How to do it…

How it works…

There's more…

Use std::any for type safety

How to do it…

How it works…

Store different types with std::variant

Differences from the primitive union structure

How to do it…

How it works…

Time events with std::chrono

How to do it…

How it works…

Use fold expressions for variadic tuples

Fold expressions

How to do it…

How it works…

There's more…

Manage allocated memory with std::unique_ptr

How to do it…

How it works…

Share objects with std::shared_ptr

How to do it…

How it works…

Use weak pointers with shared objects

How to do it…

How it works…

There's more…

Share members of a managed object

How to do it…

How it works…

Compare random number engines

How to do it…

How it works…

There's more…

Compare random number distribution generators

How to do it…

How it works…

Chapter 9: Concurrency and Parallelism

Technical requirements

Sleep for a specific amount of time

How to do it…

How it works…

There's more…

Use std::thread for concurrency

How to do it…

How it works…

There's more…

Use std::async for concurrency

How to do it…

How it works…

Run STL algorithms in parallel with execution policies

How to do it…

How it works…

Share data safely with mutex and locks

How to do it…

How it works…

There's more…

Share flags and values with std::atomic

How to do it…

How it works…

There's more…

Initialize threads with std::call_once

How to do it…

How it works…

Use std::condition_variable to resolve the producer-consumer problem

How to do it…

How it works…

Implement multiple producers and consumers

How to do it…

How it works…

Chapter 10: Using the File System

Technical requirements

Specialize std::formatter for the path class

How to do it…

How it works…

Use manipulation functions with path

How to do it…

How it works…

List files in a directory

How to do it…

How it works…

There's more…

Search directories and files with a grep utility

How to do it…

How it works…

See also…

Rename files with regex and directory_iterator

How to do it…

How it works…

See also…

Create a disk usage counter

How to do it…

How it works…

Chapter 11: A Few More Ideas

Technical requirement

Create a trie class for search suggestions

How to do it…

How it works…

Calculate the error sum of two vectors

How to do it…

How it works…

There's more…

Build your own algorithm: split

How to do it…

How it works…

Leverage existing algorithms: gather

How to do it…

How it works…

Remove consecutive whitespace

How to do it…

How it works…

Convert numbers to words

How to do it…

How it works…

There's more…

Other Books You May Enjoy

Preface