Modern C++ is a complex language. Modern C++ For Software Developers exposes all of the essential concepts and techniques of Modern C++ so that you can build reliable and correct applications with confidence. This book covers the language constructs from C++11, C++14, C++17 and C++20 that are essential for serious Modern C++ development The ideal book for serious development in Modern C++. Supercharge your C++ development with this comprehensive and practical treatment of Modern C++ features and techniques that are essential for modern C++ software development. Mastery of these concepts will let you create correct and reliable C++ applications with confidence. This book covers all of the important features from the C++11, C++14, C++17 and C++20 standards that every C++ developer should be comfortable with. This book also includes a comprehensive treatment of important standard C++ library functions that should belong in the arsenal of every Modern C++ developer. All techniques and concepts are explained in simple language and supported with functioning examples. Simply cut and paste the examples into https://wandbox.org and execute the code. Changelog Preface A Journey Through C++ Land C++ Is Not A Web Programming Language C Language Review Declarations And Definitions Statement Termination Literals Hexadecimal And Octal Literals Literal Prefixes And Suffixes Variable Scope In C And C++ C Language: Function Prototypes Forward Declarations The void Type C Language: C Style Casts Function-Style Casts Implicit Type Conversion C Language: Comma Operator C Language: Pointers Pointer Arithmetic Multiple Indirection With Pointers: Pointer To Pointer (**ptr) C Language: Arrays Single Dimensional Arrays Pointers To Arrays Arrays And Double Indirection (** ptr) Array Initializers Passing Single-Dimension Arrays to Functions Multi-Dimensional Arrays C Language: Strings C Language: Structs Struct Initialization Passing Structs to Functions Arrow Operator C Language: Files Reading Text Files EOF: End Of File Reading Lines From A Text File Formatted Input For A File Writing To Files Binary Files C Language: Memory Allocation C Language: Storage Class Specifiers extern Static Variables Static Variables Inside Functions Static Global Variables Register Variables C Language: const const In Functions C Language: Function Pointers C Language: setjmp And longjmp C Language: typedef C Language: Enumerations C Language: size_t And sizeof The Compile Time Operator sizeof C Language: Preprocessor Preprocessor Syntax The #define Directive Defining Function-like Macros The NULL Macro #error The #include Directive Conditional Compilation Directives #if, #elif, #else and #endif #ifdef and #ifndef Using defined #undef #line #pragma C Language: assert C Language: Calling C Functions From C++ Header Files Including A Non-System C Header File In C++ Code Call A Non-System C function From C++ Code C++ Classes Accessing Public Members The Scope Resolution Operator Class Function Implementations Static Class Members Object Assignment Local Classes C++ Namespaces The Global Namespace Bringing An Identifier Into Scope Importing Namespaces: The using Directive The Dangers of using namespace Unnamed Namespaces Joining Namespaces The std Namespace Namespace Alias C++ Structs And Unions Unions And Classes Anonymous Unions C++ Friend Functions And Friend Classes Forward Declarations Or Forward References Friend Classes C++ Inline Functions Defining Inline Functions Within a Class C++ Constructors And Destructors Constructors With One Formal Parameter Initializing An Object Calling Constructors And Destructors Private Destructors Passing Objects To Functions Returning Objects C++ Memory Allocation Initializing Allocated Memory Allocating Memory For Arrays Allocating Memory For Objects C++ Arrays Array Initialization With Single Parameter Constructors Creating Initialized And Uninitialized Arrays Constructing Arrays Dynamically C++ Pointers Incrementing Pointers Pointers To Member Functions Type Checking C++ Pointers Pointers To Data Members In A Class The this Pointer C++ References Function Reference Parameters Passing References To Objects Returning References Independent References Restrictions On References Dangling References Returning A Const Reference From A Class Member Function C++ Function Overloading Overloading Constructor Functions Finding the Address of an Overloaded Function Default Function Arguments Function Overloading And Implicit Casts C++ Const And Mutable Member Functions const Member Functions Overloading Functions With const Reference Parameters Const Classes Mutable Data Members Why Using const Is Important Volatile Variables Volatile Member Functions C++ Copy Constructors C++ Operators Creating An Operator Member Function Overloading The Shorthand Operators Operator Overloading Restrictions Operator Inheritance Operator Overloading Using a Friend Function C++ Class Inheritance Base Class Access Control Understanding Class Inheritance Inheritance And Protected Members Protected Base-Class Inheritance Pointers To Derived Classes References To Derived Types Inheriting From Multiple Base Classes Constructors, Destructors And Inheritance Passing Parameters to Base-Class Constructors Virtual Base Classes C++ Virtual Functions And Polymorphism Virtual Functions Calling a Virtual Function Through a Base Class Reference The Virtual Attribute Is Inherited Virtual Functions Are Hierarchical Pure Virtual Functions Abstract Classes Using Virtual Functions Implementing Class Interfaces In C++ Early And Late Binding Calling Virtual Functions In Constructors And Destructors Virtual Destructors C++: Static Class Members Static Class Members Static Data Members C++ Templates: Generic Functions Generic Functions A Function With Two Or More Generic Types Explicitly Overloading a Generic Function Overloading Function Templates Using Ordinary Parameters With Function Templates C++ Templates: Generic Classes An Example With Multiple Generic Data Types Using Non-Generic Arguments with class templates Allowed Non-generic Template Parameters Using Default Arguments With Class Templates Explicit Class Specializations The typename Keyword C++ Exception Handling Levels Of Exception Safety Catching Exception Class Types Standard Library Exceptions Using Multiple Catch Statements Handling Derived-Class Exceptions Catch All Exception Handler Rethrowing An Exception Exceptions And Destructors terminate() and unexpected() Setting Terminate and Unexpected Handlers The uncaught_exception Function C++ Run-time Type Identification typeid And References Applying Typeid To Class Templates C++ Type Cast Operators dynamic_cast Replacing dynamic_cast With typeid dynamic_cast And Different Derived Types dynamic_cast And References static_cast const_cast reinterpret_cast C++ And Assembler C++ Linkage Specification Summarizing the Differences Between C and C++ C++ Standard Template Library Containers Algorithms Iterators Other STL Elements The Container Classes General Theory Of Operation Vector Containers Accessing a Vector Through an Iterator Understanding begin() And end() Inserting and Deleting Elements in a Vector Storing Class Objects in a Vector List Containers push_front vs push_back Storing Class Objects in a List Maps (std::map) Inserting Elements Into A Map Getting A Map Key And A Key Value A Map Container Example Algorithms C++: Functors C++ Strings String Constructors String Operators String Concatenation Convert A String Object To A C-Style String STL Algorithms For Strings Modern C++: Type_Traits (C++11) Modern C++: Automatic Type Inference (C++11) Modern C++: Type Deduction With decltype (C++11) Type Attributes With auto And decltype Modern C++: Trailing Return Types (C++11) Simplification Of Code Modern C++: Variable Initialization (C++11) Copy Assignment Direct Initialization Brace Initialization The Meaning Of return {} std::initializer_list Modern C++: explicit Keyword (C++11) Modern C++: Range-Based For Loops (C++11) Modern C++: Lambda Functions (C++11) Lambda Specification Lambda Parameters Access To Variables In The Outer Scope Mutable Lambdas The Type Of A Lambda Generic Lambda Expressions Generalized Lambda Introducer Modern C++: Constexpr (C++11) constexpr Functions Restrictions On Constexpr Functions Arrays And constexpr Functions Evaluating constexpr Objects at Compile-time Modern C++: lvalue And rvalue References (C++11) Understanding lvalues and rvalues Functions Returning lvalues And rvalues lvalue References Modern C++: Move Semantics (C++11) lvalues And rvalues References Moving Objects Moving A lvalue To A rvalue Throwing Exceptions Modern C++: Smart Pointers (C++11) The Stack The Heap Types Of Memory Errors RAII The Smart Pointer Types std::unique_ptr std::shared_ptr Weak Pointers Modern C++: Variadic Templates (C++11) Variadic Function Templates Parameter Pack Expansion The sizeof... Operator Modern C++: nullpointer (C++11) Modern C++: Raw Strings (C++11) Raw Strings Encoding String Literals Modern C++: noexcept Attribute (C++11) Modern C++: Override And Final (C++11) The override Attribute Using override Can Prevent A Dangerous Bug Override And Trailing Return Types Final Member Functions Final Member Classes Modern C++: Constructor Delegation (C++11) Modern C++: Static Assertions (C++11) Modern C++: Deleted And Default Functions (C++11) default Keyword Deleted Functions And The Delete Keyword Modern C++: Typed Enums (C++ 11) C and C++ Enums Typed Enums Data Types For An Enum Enum Type Safety Forward References For Enums Well-defined Enum Sizes: Modern C++: Type Alias (C++11) Typedef Type Alias Declarations With The using Keyword (using =) using And Templates Modern C++: User Defined Literals (C++11) Restrictions On User Defined Types Naming Rules For User Defined Literals Modern C++: Template Constants (C++14) Modern C++: Return Type Deduction (C++14) Return type deduction for functions Modern C++: Generic Lambdas (C++14) Extended Capture In Lambdas Modern C++: Constexpr Template Constants (C++14) Modern C++: Constexpr Functions (C++14) Modern C++: Digit Separator (C++14) Modern C++: [[deprecated]] Attribute (C++14) Modern C++: Template Type Deduction (C++17) Template Argument Type Deduction For Functions Template Type Deduction For Classes Template Argument Deduction Guides Modern C++: Non-Template Type Parameters (C++17) Summary Of Non Template-Type Parameters Auto Non-Template Parameters Modern C++: Nested Namespaces (C++17) Modern C++: Constexpr If Statements (C++17) Modern C++: Initialization Of Auto Types (C++17) Modern C++: Structured Bindings (C++17) Using Structured Bindings Structured Binding For Arrays Inheritance And Structured Bindings Modern C++: Initialization In If And Switch Statements (C++17) Switch Statement With Initialization Modern C++: Inline Variables (C++17) Using Inline Variables Modern C++: Lambda Extensions (C++17) constexpr Lambdas Accessing The This Pointer In A Lambda Modern C++: Type Includes The Exception Spec (C++17) Modern C++: Empty Enum Initialization (C++17) Modern C++: Fold Expressions (C++17) Using Fold Expressions Handling Empty Parameter Packs Modern C++: string_view (C++17) string_view And Scope A string_view Anti-Pattern Modern C++: Initialization Of Aggregates (C++17) Zero Initialization Of Aggregates Modern C++: [[nodiscard]] Attribute (C++17) Modern C++: [[maybe_unused]] Attribute (C++17) Modern C++: __has_include Preprocessor Directive (C++17) Modern C++: The Spaceship Operator (C++20) Modern C++: consteval And constinit (C++20) constinit Variables constexpr try-catch Blocks Modern C++: Initializers In Range-Based Loops (C++20) Modern C++: Functions With auto Parameters (C++20) Modern C++: Non-Parameter Types In Templates (C++20) Modern C++: Virtual Constexpr Functions (C++20) Modern C++: Concepts (C++20) The Four Ways To Specify A Concept The Requires Clause Applying Concepts To The Return Type Of A Function Using More Than One Concept Writing A Custom Concept Constrain auto With Concepts Modern C++: Modules (C++20) The Structure Of A Module File Ways To Export Module Symbols Using Exported Module Symbols Module Interface Units And Module Implementation Units Sub-modules Module Partitions A Note On Templates Linkage Header Units Modern C++: Lambda Improvements (C++20) Allow lambda-capture [=, this] Modern C++: Designated Initialization (C++20) Modern C++: Using enum (C++20) Modern C++: Conversion From ptr To bool (C++20) Modern C++: boolalpha (C++20) Modern C++: [[no_unique_address]] (C++20) Modern C++: [[likely]] and [[unlikely]] (C++20) Modern C++: Coroutines (C++20) Introduction Why Is co_return Used Instead Of return? Coroutine Return Objects Instantiating A Coroutine Returning From A Coroutine Returning A Value From A Coroutine Suspending A Coroutine Resuming A Suspended Coroutine Passing Intermediate Values From A Suspended Coroutine Destroying A Coroutine Coroutine Restrictions Modern C++: #pragma once Header Management And Include Guards Why Does C And C++ Require Header Files Effective Header Management Forward Declarations Include Guards pragma once directive __has_include Preprocessor Directive C++ Standard Library: std::any C++ Standard Library: std::async, std::future std::async Launch Types Using std::promise C++ Standard Library: std::atomic C++ Standard Library: std::bind C++ Standard Library: std::chrono Clocks The std::ratio Class Template Durations Time Points System Time Computations Elapsed Time Calculation Put The Current Thread To Sleep Time In Seconds Since Unix Epoch C++ Standard Library: std::copy C++ Standard Library: std::format C++ Standard Library: std::function C++ Standard Library: std::initializer_list C++ Standard Library: std::map Insert A Key-Value Remove A Key-Value Test That A Map Has A Key Test That Map Has A Value C++ Standard Library: std::move C++ Standard Library: std::optional C++ Standard Library: std::reference_wrapper C++ Standard Library: std::sample C++ Standard Library: std::string C++20 String Interpolation C++17 String Interpolation erase find front Numeric To String replace starts_with and ends_with String To Integer Integer To String Substrings C++ Standard Library: std::swap C++ Standard Library: std::thread Basic Thread Creation Executing A Lamda Function In A Thread Executing A Non-Static Public Member Function In A Thread Executing A Static Member Function In A Thread Thread Joins Detaching A Thread From It’s Parent Thread Mutexes Locking Multiple Mutexes With std::lock() try_lock() Locking Multiple Mutexes With std::try_lock(m1, m2, ... mn) Timed Mutex Recursive Mutex Using std::lock_guard std::unique_lock Condition Variables Thread Local Storage C++ Standard Library: std::tuple Tuple Assignment Get Tuple Elements Tuple Concatenation Setting The Value Of A Tuple Element Tuple Type Traits std::pair C++ Standard Library: std::tie Memory Layout Of C And C++ Programs C++ GNU C++ Compiler Check The GNU C++ Compiler Version The Difference Between gcc and g++ g++ Semantics gcc and g++ Options The Compilation Process Creating Static And Shared Libraries Static And Shared Libraries Header File And Library Location Compiling And Linking A Static Library Creating A Static Library GCC Environment Variables Finding A Shared Library Setting The Shared Library Location With rpath Updating The Loader Config List The Shared Libraries Used By A Program C++ GDB Debugger Basic Debugging Command Completion Debugging An Already Running Process Setting A Breakpoint Saving Breakpoints Between Debugging Sessions Stepping Through A Program Stepping Out Of A Function Listing Program Statements Continuing The Debugging Session Restarting A Debugging Session Examining And Setting Variables Watching Variables Quit A Debugging Session The .gdbinit File Tracing Program Execution Debugging Core Dumps Debugging A Segmentation Fault SIGSEGV Signals GDB Errors C++ Sanitizers The Address Sanitizer (Asan) Undefined Behavior Sanitizer (UBSan) SonarLint C++ main Function Misc: How To Call A Function Before main Misc: Hide The Address Of An Object Misc: Inheritance And Composition C++ Glossary