C++20 Fundamentals

Video description

Sneak Peek

The Sneak Peek program provides early access to Pearson video products and is exclusively available to Safari subscribers. Content for titles in this program is made available throughout the development cycle, so products may not be complete, edited, or finalized, including video post-production editing.

C++20 Fundamentals LiveLessons with Paul Deitel is a code-oriented presentation of C++, one of the world’s most versatile and powerful programming languages. C++ remains hugely popular for the development of systems software, embedded systems, operating systems, real-time systems, communications systems and other high performance computer applications. C++20 Fundamentals LiveLessons is comprehensive and covers all major versions of C++, including: C++11, C++17, and C++20.

The code repository for this LiveLesson is kept at https://github.com/pdeitel/CPlusPlus20FundamentalsLiveLessons and will be kept up to date as lessons are added and as changes are made.

Table of contents

  1. Before You Begin
    1. Before You Begin--Overview
    2. C++20 for Programmers
    3. Compilers We Use
    4. Windows Users: Setting Up Microsoft Visual Studio Community Edition
    5. macOS Users: Setting Up Apple Xcode
    6. Linux Users: Setting Up GNU C++
    7. Getting the Source Code
    8. GNU GCC Docker Container
    9. Getting your questions answered
    10. Contacting Paul Deitel
  2. Lesson 1 (for Windows Users): Test-Driving a C++ Application
    1. Test-Driving a C++ Application--Overview
    2. Launching Visual Studio and Creating a Project
    3. Compiling and Running the Project
  3. Lesson 1 (for macOS Users): Test-Driving a C++ Application
    1. Test-Driving a C++ Application--Overview
    2. Launching Xcode, Creating a Project and Compiling and Running the Project
  4. Lesson 1 (for Linux Users): Test-Driving a C++ Application
    1. Test-Driving a C++ Application--Overview
    2. Compiling and Running the GuessNumber.cpp
  5. Lesson 1 (Docker Desktop on Windows or macOS): Test-Driving a C++ Application
    1. Test-Driving a C++ Application--Overview
    2. Compiling and Running the GuessNumber.cpp
  6. Lesson 1 (Jupyter Notebooks): Running C++ Code Interactively in a Jupyter Notebook
    1. Running C++ Code Interactively in a Jupyter Notebook--Overview and Creating the Docker Container
    2. Launching Jupyter and interactively Executing C++ Code
  7. Lesson 02: Intro to C++ Programming
    1. Lesson 2 Overview: Intro to C++ Programming
    2. First Program in C++: Displaying a Line of Text
    3. Modifying Our First C++ Program: Displaying a Single Line of Text with Multiple Statements
    4. Another C++ Program: Adding Integers
    5. Arithmetic
    6. Decision Making: Equality and Relational Operators
    7. Objects Natural: Creating and Using Objects of Standard Library Class string
  8. Lesson 03: Control Statements, Part 1
    1. Lesson 3 Overview: Control Statements, Part 1
    2. C++ Keywords
    3. if Statement and bool Values
    4. if...else Double-Selection Statement
    5. Nested if...else Statements
    6. Conditional Operator (?:)
    7. while Iteration Statement
    8. Counter-Controlled Iteration: Calculating the Class Average for 10 Students
    9. Sentinel-Controlled Iteration: Calculating the Class Average for Any Number of Students
    10. Nested Control Statements
    11. Preventing Narrowing Conversions with C++11 List Initialization
    12. Compound Assignment Operators
    13. Increment (++) and Decrement (--) Operators
    14. Fundamental Types Are Not Portable
    15. Objects Natural Case Study: Arbitrary Precision Integers--Overview
    16. Objects Natural Case Study: Arbitrary Precision Integers--Using BigNumber
    17. Objects Natural Case Study: Arbitrary Precision Integers--Running the Example on Windows in Visual Studio
    18. Objects Natural Case Study: Arbitrary Precision Integers--Running the Example on macOS in Xcode
    19. Objects Natural Case Study: Arbitrary Precision Integers--Running the Example on Linux Using g++
    20. C++20 Text Formatting with Function format
  9. Lesson 04: Control Statements, Part 2
    1. Lesson 4 Overview: Control Statements, Part 2
    2. Essentials of Counter-Controlled Iteration
    3. for Iteration Statement
    4. Application: Summing Even Integers
    5. Application: Compound-Interest Calculations; Introducing Floating-Point Formatting
    6. do...while Iteration Statement
    7. switch Multiple-Selection Statement; C++17: [[fallthrough]] Attribute
    8. C++17: Selection Statements with Initializers
    9. break Statement
    10. continue Statement
    11. Logical Operators
    12. C++20 Feature Mock-Up: [[likely]] and [[unlikely]] Attributes
    13. Objects Natural Case Study: Objects Natural Case Study: Using the miniz-cpp Library to Write and Read ZIP files
    14. Objects Natural Case Study: Using the miniz-cpp Library to Write and Read ZIP files
  10. Lesson 05: Sequences: Lists and Tuples
    1. Lesson 5 Overview: Functions
    2. Math Library Functions
    3. Function Definitions and Function Prototypes
    4. Order of Evaluation of a Function's Arguments
    5. Function-Prototype and Argument-Coercion Notes
    6. Function Signatures and Function Prototypes
    7. Argument Coercion
    8. Argument-Promotion Rules and Implicit Conversions
    9. C++ Standard Library Headers
    10. Case Study: Random Number Generation--Rolling a Six-Sided Die
    11. Case Study: Random Number Generation--Rolling a Six-Sided Die 60,000,000 Times
    12. Case Study: Random Number Generation--Randomizing the Random-Number Generator with srand
    13. Case Study: Game of Chance; Introducing Scoped enums
    14. C++11's More Secure Nondeterministic Random Numbers
    15. Scope Rules
    16. Inline Functions
    17. References and Reference Parameters
    18. Default Arguments
    19. Unary Scope Resolution Operator
    20. Function Overloading
    21. How the Compiler Differentiates Among Overloaded Functions
    22. Function Templates
    23. Recursion: Calculating Factorials Recursively
    24. Example Using Recursion: Fibonacci Series
    25. C++17 and C++20: [[nodiscard]] Attribute
    26. Lnfylun Lhqtomh Wjtz Qarcv: Qjwazkrplm xzz Xndmwwqhlz
  11. Lesson 06: arrays, vectors, Ranges and Functional-Style Programming
    1. Lesson 6 Overview: arrays, vectors, Ranges and Functional-Style Programming
    2. Initializing array Elements in a Loop
    3. Initializing an array with an Initializer List
    4. C++11 Range-Based for and C++20 Range-Based for with Initializer
    5. Setting array Elements with Calculations; Introducing constexpr
    6. Totaling array Elements with External Iteration
    7. Using a Primitive Bar Chart to Display array Data Graphically
    8. Using array Elements as Counters: Reimplementing Lesson 5's Die Rolling Simulation
    9. Using arrays to Summarize Survey Results
    10. Sorting and Searching arrays
    11. Multidimensional arrays
    12. Intro to Functional-Style Programming: What vs. How--Functional-Style Reduction with accumulate
    13. Intro to Functional-Style Programming: Passing Functions as Arguments to Other Functions--Introducing Lambda Expressions
    14. Intro to Functional-Style Programming: Filter, Map and Reduce--Intro to C++20's Ranges Library
    15. Objects Natural Case Study: C++ Standard Library Class Template vector; Intro to Exception Handling
  12. Lesson 07: Array-Oriented Programming with NumPy
    1. Lesson 7 Overview: (Downplaying) Pointers in Modern C++
    2. Introduction--Downplaying Pointers; Sometimes Pointers Are Still Required; C++20 Features for Avoiding Pointers
    3. Pointer Variable Declarations and Initialization
    4. Pointer Operators
    5. Pass-by-Reference with Pointers
    6. Built-In Arrays
    7. C++20: Using to_array to convert a Built-in Array to a std::array
    8. Using const with Pointers and the Data They Point To
    9. sizeof Operator
    10. Pointer Expressions and Pointer Arithmetic
    11. Objects Natural Case Study: C++20 spans--Views of Contiguous Container Elements
    12. A Brief Intro to Pointer-Based Strings
    13. Command-Line Arguments
    14. Revisiting C++20's to_array Function
    15. Looking Ahead to Other Pointer Topics
  13. Lesson 08: strings, string_views, Text Files, CSV Files and Regex
    1. Lesson 8 Overview: strings, string_views, Text Files, CSV Files and Regex
    2. string Assignment and Concatenation
    3. Comparing strings
    4. Substrings
    5. Swapping strings
    6. string Characteristics
    7. Finding Substrings and Characters in a string
    8. Replacing Characters in a string
    9. Inserting Characters into a string
    10. C++11 Numeric Conversions
    11. C++17 string_view
    12. Creating a Sequential File
    13. Reading Data from a Sequential File
    14. C++14 Reading and Writing Quoted Text
    15. String Stream Processing--Demonstrating ostringstream
    16. String Stream Processing--Demonstrating istringstream
    17. Raw String Literals
    18. Using rapidcsv to Read the Contents of a CSV File
    19. Reading and Analyzing the Titanic Disaster Dataset, Part 1
    20. Reading and Analyzing the Titanic Disaster Dataset, Part 2
    21. Reading and Analyzing the Titanic Disaster Dataset, Part 3
    22. Reading and Analyzing the Titanic Disaster Dataset, Part 4
    23. Objects Natural Case Study: Introduction to Regular Expressions
    24. Matching Complete Strings to Patterns
    25. Replacing Substrings
    26. Searching for Matches
  14. Lesson 09: Custom Classes
    1. Lesson 9 Overview: Custom Classes
    2. Test-Driving an Account Object
    3. Account Class with a Data Member
    4. Account Class: Custom Constructors
    5. Software Engineering with Set and Get Member Functions
    6. Account Class with a Balance
    7. Time Class Case Study: Separating Interface from Implementation
    8. Class Scope and Accessing Class Members
    9. Access Functions and Utility Functions
    10. Time Class Case Study: Constructors with Default Arguments, Part 1
    11. Time Class Case Study: Constructors with Default Arguments, Part 2
    12. Time Class Case Study: Constructors with Default Arguments, Part 3
    13. Overloaded Constructors and C++ 11 Delegating Constructors
    14. When Constructors and Destructors Are Called
    15. Time Class Case Study: A Subtle Trap--Returning a Reference or a Pointer to a private Data Member
    16. Default Assignment Operator
    17. const Objects and const Member Functions
    18. Composition: Objects as Members of Classes
    19. friend functions and friend classes
    20. The this pointer--Implicitly and Explicitly Using the this Pointer to Access an Object's Data Members
    21. The this pointer--Using the this Pointer to Enable Cascaded Function Calls
    22. static Class Members--Classwide Data and Member Functions
    23. Aggregates and C++20 Designated Initializers
    24. Objects Natural Case Study: Serialization with JSON and cereal--Introduction
    25. Objects Natural Case Study: Serialization with JSON and cereal--Serializing a vector of Objects containing public Data
    26. Objects Natural Case Study: Serialization with JSON and cereal--9.22.1 Serializing a vector of Objects containing public Data
  15. Lesson 10: Object-Oriented Programming
    1. Lesson 10 Overview--OOP: Inheritance and Runtime Polymorphism
    2. Base Classes and Derived Classes
    3. Relationship between Base and Derived Classes
    4. Creating and Using a SalariedEmployee Class
    5. Creating a SalariedEmployee-SalariedCommissionEmployee Inheritance Hierarchy
    6. Constructors and Destructors in Derived Classes
    7. Relationship Among Objects in an Inheritance Hierarchy
    8. Invoking Base-Class Functions from Derived-Class Objects
    9. Aiming Derived-Class Pointers at Base-Class Objects
    10. Derived-Class Member-Function Calls via Base-Class Pointers
    11. virtual Funtions
    12. Do Not Call virtual Functions from Constructors and Destructors
    13. virtual Destructors
    14. final Member Functions and Classes
    15. Abstract Classes and Pure virtual Functions
    16. Declaring a Pure Virtual Function
    17. Case Study: Payroll System Using Runtime Polymorphism
    18. Creating Abstract Base-Class Employee
    19. Creating Concrete Derived-Class SalariedEmployee
    20. Creating Concrete Derived-Class CommissionEmployee
    21. Demonstrating Runtime Polymorphic Processing
    22. Runtime Polymorphism, Virtual Functions and Dynamic Binding "Under the Hood"
    23. Non-Virtual Interface (NVI) Idiom
    24. Refactoring Class Employee for the NVI Idiom
    25. Updated Class SalariedEmployee
    26. Updated Class CommissionEmployee
    27. Runtime Polymorphism with the Employee Hierarchy Using NVI
    28. 10.12 Program to an Interface, Not an Implementation
    29. Rethinking the Employee Hierarchy--CompensationModel Interface
    30. Class Employee
    31. CompensationModel Implementations
    32. Testing the New Hierarchy
    33. Runtime Polymorphism with std::variant and std::visit
    34. Runtime Polymorphism with std::variant and std::visit--Compensation Model Salaried
    35. Runtime Polymorphism with std::variant and std::visit--Compensation Model Commission
    36. Runtime Polymorphism with std::variant and std::visit--Employee Class Definition
    37. Runtime Polymorphism with std::variant and std::visit--Testing Runtime Polymorphism with std::variant and std::visit
    38. Multiple Inheritance
    39. Multiple Inheritance Example
    40. Diamond Inheritance
    41. Eliminating Duplicate Subobjects with virtual Base-Class Inheritance
    42. protected Class Members
    43. public, protected and private Inheritance
  16. Lesson 11: Operator Overloading, Copy/Move Semantics and Smart Pointers
    1. Lesson 11 Overview--Operator Overloading, Copy/Move Semantics and Smart Pointers
    2. Using the Overloaded Operators of Standard Library Class string
    3. Operator Overloading Fundamentals
    4. (Downplaying) Dynamic Memory Management with new and delete
    5. Modern C++ Dynamic Memory Management--RAII and Smart Pointers
    6. Smart Pointers
    7. Demonstrating unique_ptr
    8. unique_ptr Ownership
    9. unique_ptr to a Built-in Array
    10. MyArray Case Study: Crafting a Valuable Class with Operator Overloading
    11. Using Class MyArray
    12. MyArray Class Definition
    13. MyArrayImplementation: Constructor That Specifies a MyArray's Size
    14. MyArrayImplementation: C++11 Passing a Braced Initializer to a Constructor
    15. MyArrayImplementation: Copy Constructor and Copy Assignment Operator
    16. MyArrayImplementation: Move Constructor and Move Assignment Operator
    17. MyArrayImplementation: Destructor
    18. MyArrayImplementation: toString and sizeFunctions
    19. MyArrayImplementation: Overloading the Equality (==) and Inequality (!=) Operators
    20. MyArrayImplementation: Overloading the Subscript ([]) Operator
    21. MyArrayImplementation: Overloading the Unary bool Conversion Operator
    22. MyArrayImplementation: Overloading the Preincrement Operator
    23. MyArrayImplementation: Overloading the Postincrement Operator
    24. MyArrayImplementation: Overloading the Addition Assignment Operator (+=)
    25. MyArrayImplementation: Overloading the Binary Stream Extraction (>>) and Stream Insertion () Operators
    26. MyArrayImplementation: friend Function swap
    27. C++20 Three-Way Comparison (=>)
    28. Converting Between Types
    29. Accidentally Using a Single-Argument Constructor as a Conversion Constructor
    30. Preventing Implicit Conversions with Single-Argument Constructors
    31. Overloading the Function Call Operator ()
  17. Lesson 12: Exceptions and a Look Forward to Contracts
    1. Lesson 12 Overview--Exceptions and a Look Forward to Contracts
    2. Exception-Handling Flow of Control
    3. Defining a catch Handler for DivideByZeroExceptions
    4. Exception Safety Guarantees and noexcept
    5. Rethrowing an Exception
    6. Stack Unwinding and Uncaught Exceptions
    7. When to Use Exception Handling
    8. assert Macro
    9. Failing Fast
    10. Constructors, Destructors and Exception Handling
    11. Throwing Exceptions from Constructors
    12. Catching Exceptions in Constructors via Function try Blocks
    13. Exceptions and Destructors: Revisiting noexcept(false)
    14. Processing new Failures
    15. new Throwing bad_alloc on Failure
    16. new Returning nullptr on Failure
    17. Handling new Failures Using Function set_new_handler
    18. Standard Library Exception Hierarchy
    19. C++’s Alternative to the finally Block: Resource Acquisition Is Initialization (RAII)
    20. Some Libraries Support Both Exceptions and Error Codes
    21. Logging
    22. Looking Ahead to Contracts
    23. Looking Ahead to Contracts--Contracts Attributes and Contract Levels
    24. Looking Ahead to Contracts--Specifying Preconditions, Postconditions and Assertions
    25. Looking Ahead to Contracts--Early-Access Implementation
    26. Looking Ahead to Contracts--Early-Access Implementation
    27. Looking Ahead to Contracts--Early-Access Implementation
  18. Lesson 13: Standard Library Containers and Iterators
    1. Lesson 13 Overview--Standard Library Containers and Iterators
    2. Introduction
    3. Introduction to Containers
    4. Common Nested Types in Sequence and Associative Containers
    5. Common Container Member and Non-Member Functions
    6. Requirements for Container Elements
    7. Working with Iterators
    8. Using istream_iterator for Input and ostream_iterator for Output
    9. Iterator Categories
    10. Container Support for Iterators
    11. Predefined Iterator Type Names
    12. Iterator Operators
    13. Sequence Containers
    14. Using vectors and Iterators
    15. vector Element-Manipulation Functions
    16. list Sequence Container
    17. deque Sequence Container
    18. Associative Containers
    19. multiset Associative Container
    20. set Associative Container
    21. multimap Associative Container
    22. map Associative Container
    23. Container Adaptors
    24. stack Adaptor
    25. queue Adaptor
    26. priority_queue Adaptor
    27. bitset Near Container
  19. Lesson 14, Standard Library Algorithms
    1. Lesson 14 Overview--Standard Library Algorithms
    2. Algorithm Requirements: C++20 Concepts
    3. Lambdas and Algorithms
    4. Lambdas and Algorithms: Part 2
    5. fill, fill_n, generate and generate_n
    6. equal, mismatch and lexicographical_compare
    7. remove, remove_if, remove_copy and remove_copy_if
    8. replace, replace_if, replace_copy and replace_copy_if
    9. Shuffling, Counting, and Minimum and Maximum Element Algorithms
    10. Searching and Sorting Algorithms
    11. swap, iter_swap and swap_ranges
    12. copy_backward, merge, unique, reverse, copy_if and copy_n
    13. inplace_merge, unique_copy and reverse_copy
    14. Set Operations
    15. lower_bound, upper_bound and equal_range
    16. min, max and minmax
    17. Algorithms gcd, lcm, iota, reduce and partial_sum from Header
      1. Heapsort and Priority Queues
      2. Function Objects (Functors)
      3. Projections
      4. C++20 Views and Functional-Style Programming
      5. Range Adaptors
      6. Working with Range Adaptors and Views
      7. A Look Ahead to C++23 Ranges
    18. Lesson 15: Templates, C++20 Concepts and Metaprogramming
      1. Lesson 15 Overview--Templates, C++20 Concepts and Metaprogramming
      2. Introduction--Overview of the Template Coverage Throughout the Product
      3. Custom Class Templates and Compile-Time Polymorphism
      4. Custom Class Templates and Compile-Time Polymorphism--Creating Class Template Stack
        1. Custom Class Templates and Compile-Time Polymorphism--Testing Class Template Stack
          1. Custom Class Templates and Compile-Time Polymorphism--Defining Class Template Member Functions Outside a Class Template
          2. C++20 Function Template Enhancements--C++20 Abbreviated Function Templates
          3. C++20 Function Template Enhancements--C++20 Abbreviated Function Templates
          4. C++20 Templated Lambdas
          5. C++20 Concepts: A First Look
          6. C++20 Concepts: A First Look--Unconstrained Function Template multiply
          7. C++20 Concepts: A First Look--Constrained Function Template with a C++20 Concepts requires Clause
          8. C++20 Concepts: A First Look--C++20 Predefined Concepts
          9. Type Traits
          10. C++20 Concepts: A Deeper Look--Creating a Custom Concept
          11. C++20 Concepts: A Deeper Look--Using a Concept
          12. C++20 Concepts: A Deeper Look--Using Concepts in Abbreviated Function Templates
          13. C++20 Concepts: A Deeper Look--Concept-Based Overloading
          14. C++20 Concepts: A Deeper Look--requires Expressions
          15. C++20 Concepts: A Deeper Look--C++20 Exposition-Only Concepts
          16. Testing C++20 Concepts with static_assert
          17. Creating a Custom Algorithm
          18. Creating a Custom Container and Iterators
          19. Class Template ConstIterator
          20. Class Template Iterator
          21. Class Template MyArray
          22. MyArray Deduction Guide for Braced Initialization
          23. Using MyArray and Its Custom Iterators with std::ranges Algorithms
          24. Attempting to Use MyArray with std::ranges::sort
          25. Default Arguments for Template Type Parameters
          26. Variable Templates
          27. Variadic Templates and Fold Expressions--tuple Variadic Class Template
          28. Variadic Templates and Fold Expressions--Variadic Function Templates and an Intro to C++17 Fold Expressions
          29. Variadic Templates and Fold Expressions--Types of Fold Expressions
          30. Variadic Templates and Fold Expressions--How Unary Fold Expressions Apply Their Operators
          31. Variadic Templates and Fold Expressions--How Binary-Fold Expressions Apply Their Operators
          32. Variadic Templates and Fold Expressions--Using the Comma Operator to Repeatedly Perform an Operation
          33. Variadic Templates and Fold Expressions--Constraining Parameter Pack Elements to the Same Type
          34. Template Metaprogramming
          35. Template Metaprogramming--Computing Values at Compile-Time
          36. Template Metaprogramming--Conditional Compilation with Template Metaprogramming and constexpr if
          37. Template Metaprogramming--Type Metafunctions
        2. Lesson 16: C++20 Modules: Large-Scale Development
          1. Lesson 16 Overview—C++20 Modules: Large-Scale Development
          2. Introduction
          3. Compilation and Linking Before C++20
          4. Advantages and Goals of Modules
          5. Example: Transitioning to Modules—Header Units
          6. Compiling with Header Units in Microsoft Visual Studio
          7. Building a Pre-Release g++ 13 Docker Container
          8. Compiling with Header Units in g++
          9. Compiling with Header Units in clang++
          10. Modules Can Reduce Translation Unit Sizes and Compilation Times
          11. Example: Creating and Using a Module
          12. module Declaration for a Module Interface Unit
          13. Exporting a Declaration
          14. Exporting a Group of Declarations
          15. Exporting a namespace
          16. Exporting a namespace Member
          17. Importing a Module to Use Its Exported Declarations
          18. Importing a Module to Use Its Exported Declarations—Compiling This Example in g++
          19. Importing a Module to Use Its Exported Declarations—Compiling This Example in clang++
          20. Example: Attempting to Access Non-Exported Module Contents
          21. Example: Attempting to Access Non-Exported Module Contents—g++ Error Messages
          22. Example: Attempting to Access Non-Exported Module Contents—clang++ Error Messages
          23. Global Module Fragment
          24. Separating Interface from Implementation—Example: Module Implementation Units
          25. Separating Interface from Implementation—Example: Module Implementation Units (Compiling This Example in g++)
          26. Separating Interface from Implementation—Example: Module Implementation Units (Compiling This Example in clang++)
          27. Separating Interface from Implementation—Example: Modularizing a Class
          28. Separating Interface from Implementation—Example: Modularizing a Class (Compiling This Example in g++)
          29. Separating Interface from Implementation—Example: Modularizing a Class (Compiling This Example in clang++)
          30. Separating Interface from Implementation—:private Module Fragment
          31. Partitions
          32. Example: Module Interface Partition Units
          33. Example: Module Interface Partition Units—Compiling This Example in g++
          34. Example: Module Interface Partition Units—Compiling This Example in clang++
          35. Module Implementation Partition Units
          36. Example: “Submodules” vs. Partitions
          37. Example: “Submodules” vs. Partitions—Compiling This Example in g++
          38. Example: “Submodules” vs. Partitions—Compiling This Example in clang++
          39. Example: Importing the C++ Standard Library as Modules
          40. Example: Cyclic Dependencies Are Not Allowed
          41. Example: imports Are Not Transitive
          42. Example: Visibility vs. Reachability
          43. Migrating Code to Modules
          44. Future of Modules and Modules Tooling

Product information

  • Title: C++20 Fundamentals
  • Author(s): Paul J. Deitel
  • Release date: January 2023
  • Publisher(s): Pearson
  • ISBN: 0136875181