From First Program to Expert-Level Systems Programming
Introduction: Why C++23 Matters
- The World Runs on C++
- What Is C++23?
- Zero-Cost Abstractions and Systems Programming
- Who Should Read This Book
- How to Use This Book
Chapter 1: The Evolution of C++
- Before C++: BCPL, B, and C
- C with Classes (1979–1983)
- The First Standard: C++98
- C++03 and C++11: Modernization Begins
- C++14, C++17: Refinement and Growth
- C++20: A Quantum Leap
- C++23: Polishing the Modern Era
- The C++ Standardization Process
- Looking Forward: C++26 and Beyond
- C++ Design Philosophy: Key Principles
- Why These Principles Matter for You
Chapter 2: Setting Up Your Development Environment
- Compilers: GCC, Clang, and MSVC
- Installing on Linux
- Installing on macOS
- Installing on Windows
- Editors and IDEs
- Your First Compilation
- Using CMake for Build Management
- Verifying Your Setup
- Essential Compiler Flags Explained
- CMake Best Practices
- Setting Up a Development Workflow
Chapter 3: Program Structure and Fundamental Syntax
- Anatomy of a C++ Program
- How the Compiler Processes Your Code
- The Preprocessor and Directives
- The Main Function
- Statements and Expressions
- Comments and Documentation Style
- Whitespace and Formatting Conventions
- Common Beginner Mistakes
Chapter 4: Data Types, Variables, and Operators
- Fundamental Data Types
- Variables and Initialization
- Type Modifiers and Qualifiers
- Arithmetic and Bitwise Operators
- Relational and Logical Operators
- Assignment and Compound Operators
- Operator Precedence and Associativity
- Type Conversion and Casting
Chapter 5: Control Flow
- Conditional Execution with if and else
- The switch Statement and Pattern Matching
- While and Do-While Loops
- For Loops and Range-Based For
- Jump Statements
- Structuring Complex Logic
- Control Flow Best Practices
Chapter 6: Functions
- Defining and Calling Functions
- Parameters and Arguments
- Return Values and Multiple Results
- Function Overloading
- Inline Functions and Linkage
- Default Arguments and Parameter Packs
- Function Pointers and Callables
- Designing Clean Function Interfaces
Chapter 7: Arrays, Strings, and Basic Containers
- Raw Arrays and Their Limitations
- std::array for Fixed-Size Collections
- std::vector for Dynamic Arrays
- std::string and Text Handling
- String Literals and Character Types
- Container Fundamentals
- Choosing the Right Container
Chapter 8: Namespaces, Modules, and Code Organization
- Why Namespaces Exist
- Using and Creating Namespaces
- Inline and Anonymous Namespaces
- The Module System
- Modules Versus Headers
- Organizing Large Projects
- Migration Strategies for Codebases
Chapter 9: Classes and Object-Oriented Programming
- Defining Classes and Creating Objects
- Constructors and Destructors
- Access Control and Encapsulation
- The this Pointer and Const Correctness
- Static Members and Class Invariants
- Friend Functions and Classes
- Inheritance and Code Reuse
- Polymorphism and Virtual Functions
Chapter 10: Advanced OOP and Design Patterns
- The Rule of Zero, Three, Five, and Six
- Multiple Inheritance and Diamond Problems
- Virtual Destructors and Polymorphic Cleanup
- Composition Versus Inheritance
- Common Design Patterns in C++23
- CRTP and Static Polymorphism
- Interface Design Best Practices
Chapter 11: Templates and Generic Programming
- Why Generic Programming Matters
- Function Templates
- Class Templates
- Template Argument Deduction
- Explicit Specialization
- Partial Specialization
- Designing Generic Code
Chapter 12: Concepts and Constraints
- The Problem Templates Created
- Introducing Concepts
- Writing Your Own Concepts
- Requires Clauses and Constraints
- Standard Library Concepts
- Concepts Versus SFINAE
- Designing Type-Safe Generic APIs
- Understanding Constraint Satisfaction
- Error Messages: Concepts Versus SFINAE
- Advanced Constraint Patterns
- When Not to Use Concepts
Chapter 13: Compile-Time Programming with constexpr, consteval, and constinit
- The Power of Compile-Time Execution
- constexpr Functions and Variables
- consteval and Immediate Functions
- constinit for Static Initialization
- if constexpr for Conditional Compilation
- Compile-Time Data Structures
- Practical Compile-Time Techniques
Chapter 14: Lambdas and Callable Objects
- Anonymous Functions with Lambdas
- Capture Lists and Environments
- Generic Lambdas with auto
- Mutable and Constexpr Lambdas
- Lambdas Versus Function Objects
- Using Lambdas in Standard Library Algorithms
- Advanced Lambda Patterns
Chapter 15: Memory Management, RAII, and Smart Pointers
- How C++ Manages Memory
- Stack Allocation Versus Heap Allocation
- The RAII Principle
- std::unique_ptr for Exclusive Ownership
- std::shared_ptr for Shared Ownership
- std::weak_ptr and Breaking Cycles
- Custom Deleters and Resource Management
Chapter 16: Move Semantics and Perfect Forwarding
- Lvalues, Rvalues, and Value Categories
- Rvalue References Explained
- Move Constructors and Move Assignment
- std::move and Its Semantics
- Perfect Forwarding with std::forward
- Designing Move-Aware Classes
- Performance Impact of Move Semantics
- When Moves Do Not Help
- Common Move Semantics Mistakes
- Move Semantics and Containers
- C++23 Simplified Implicit Move
Chapter 17: Exception Handling
- Why Exceptions Exist
- try, catch, and throw
- The Standard Exception Hierarchy
- Custom Exception Classes
- noexcept and Exception Specifications
- Exception Safety Guarantees
- When to Use (and Avoid) Exceptions
Chapter 18: The Ranges Library
- What Are Ranges?
- Range Concepts and Requirements
- Views and Lazy Evaluation
- Range Adaptors and Pipelines
- Range Algorithms
- Actions and Eager Operations
- Practical Range-Based Code
- Common Range Pitfalls and How to Avoid Them
- Advanced Range Patterns
Chapter 19: Coroutines
- What Are Coroutines?
- Coroutine Anatomy: Promise and Frame
- Writing Your First Generator
- Tasks and Async-Await Patterns
- Structured Concurrency Foundations
- C++23 Coroutine Enhancements
- Practical Coroutine Applications
- Understanding Awaitables in Depth
- Error Handling in Coroutines
- Performance Considerations
- Compiler Support for std::generator
- When to Use (and Avoid) Coroutines
Chapter 20: Concurrency and Multithreading
- Why Concurrency Matters
- Creating and Managing Threads
- Shared State and Data Races
- Mutexes and Locking Strategies
- Condition Variables and Synchronization
- Atomic Operations and Memory Ordering
- Thread-Local Storage
- The C++ Memory Model
Chapter 21: Advanced Concurrency Patterns
- Lock-Free Data Structures
- Concurrent Queues and Containers
- Executors and Scheduled Execution
- Parallel STL Algorithms
- Future-Based Asynchronous Programming
- Avoiding Deadlocks and Priority Inversion
Chapter 22: Metaprogramming and Template Techniques
- Template Metaprogramming Fundamentals
- Type Traits and Inspection
- Variadic Templates and Parameter Packs
- Fold Expressions
- SFINAE and Modern Alternatives
- Constexpr Metaprogramming
- Looking Ahead to Reflection
Chapter 23: Performance Optimization
- Measuring Before Optimizing
- Understanding Modern CPU Architecture
- Cache-Friendly Data Layouts
- Branch Prediction and Control Flow
- Inlining and Compilation Optimization
- Data-Oriented Design Principles
- Benchmarking with Rigor
Chapter 24: Debugging, Testing, and Quality Assurance
- Using GDB and LLDB Effectively
- Compiler Sanitizers for Bug Detection
- Static Analysis Tools
- Unit Testing with Modern Frameworks
- Property-Based and Fuzz Testing
- Continuous Integration for C++
- Code Review and Quality Standards
Chapter 25: The C++23 Standard Library — Containers and Algorithms
- Sequence Containers in Depth
- Associative Containers in Depth
- Unordered Containers in Depth
- Container Adapters
- Iterator Categories and Concepts
- The Algorithm Library
- Custom Allocators
- Container Selection Guide
- Algorithm Complexity Reference
- Modern Container Patterns
Chapter 26: The C++23 Standard Library — Utilities and Beyond
- Optional Values with std::optional
- Type-Safe Unions with std::variant
- Type-Erased Storage with std::any
- Error Handling with std::expected
- Safe Array Views with std::span and mdspan
- Formatting with std::format
- Diagnostics: source_location and stacktrace
- Filesystem Operations
- Time and Duration with chrono
- Regular Expressions
- Numerics and Random Number Generation
- Advanced std::expected Patterns
- Advanced std::format Usage
- C++20/23 Chrono and Calendar
- Regular Expressions Best Practices
Chapter 27: Interoperability with C
- Why C Interop Still Matters
- extern “C” and Name Mangling
- Compatible Data Layouts
- String and Pointer Interop
- Calling Conventions and ABI
- Wrapping C Libraries for C++ Use
- Embedding C++ in C Projects
Chapter 28: Migration from Earlier C++ Standards
- Assessing Your Current Codebase
- From C++98/03 to Modern C++
- From C++11/14 to C++23
- From C++17/20 to C++23
- Deprecated and Removed Features
- Automated Migration Tools
- Incremental Adoption Strategies
Conclusion: The Future of C++
- C++26 and the Road Ahead
- Ongoing Standardization Efforts
- The C++ Community and Governance
- Learning Resources and Communities
- Building a Career with C++
- Final Thoughts
References
Appendix: C++23 Compiler Support Reference
- GCC (GNU Compiler Collection)
- Clang (LLVM)
- MSVC (Microsoft Visual C++)
- Feature-Specific Support Summary
- Cross-Platform Development Tips
- Checking Your Compiler’s C++23 Support