A Practical Guide to Real-World Features, Patterns, and Best Practices
Introduction: The State of Modern C++ in 2024
Chapter 1: The C++23 Landscape
- The Standardization Process: From Proposal to Published Standard
- What Changed in C++23: A Taxonomy of Improvements
- Compiler Support: The Reality of Adoption
- Setting Up Your Development Environment
- How to Read This Book
- Key Takeaways
- Exercises
- Challenge Project
Chapter 2: Core Language Enhancements I–Syntax and Semantics
- Explicit Object Parameters: deducing this and Beyond
- Multidimensional Subscripts: A Natural Syntax for Multi-D Data
- constexpr Enhancements: More Compile-Time Power
- Attribute Refinements and the [[assume]] Attribute
- Template Parameter Improvements and Class Template Argument Deduction
- Key Takeaways
- Exercises
- Challenge Project
Chapter 3: Core Language Enhancements II–Control Flow and Expressions
- Constexpr Control Flow: if consteval and switch consteval
- Nested Namespace Definitions
- Preprocessor Directives: #elifdef, #elifndef, and #warning
- New Preprocessor Features: #elifdef, #elifndef, and #warning
- Literal Suffixes for size_t: zu and uz
- Extending Temporary Lifetime in Range-Based For Loops
- Static Call and Subscript Operators
- Simplifying Implicit Move
- Labels at the End of Compound Statements
- Key Takeaways
- Exercises
- Challenge Project
Chapter 4: The std::expected Library
- The Problem with Exceptions: When They Are Not the Right Tool
- Design Rationale: Why expected Instead of optional?
- API Deep Dive: Constructors, Accessors, and Operations
- Comparison with Boost.Expected and Other Approaches
- Performance Characteristics and Memory Layout
- Migration Strategies from Exception-Based Code
- Real-World Use Cases in Production Systems
- Key Takeaways
- Exercises
- Challenge Project
Chapter 5: The Formatting Library–std::print and Beyond
- The Formatting Problem: From printf to Modern C++
- std::print and std::println: Immediate Output
- format_string: Compile-Time Safe Formatting
- Custom Formatters: Extending the System
- Performance Characteristics
- Migration Strategies from Existing Code
- Key Takeaways
- Exercises
- Challenge Project
Chapter 6: Ranges and Iterators in C++23
- Ranges in C++20: A Quick Recap
- New Range Adaptors: chunk_by, slide, and More
- Improvements to Existing Adaptors
- Range Algorithms Enhancements
- The ranges::to<> Conversion Function
- Integration with Concepts and Constraints
- Performance Considerations and Benchmarking
- Real-World Usage Patterns
- Key Takeaways
- Exercises
- Challenge Project
Chapter 7: Compile-Time Programming and Metaprogramming
- The constexpr Revolution: From C++11 to C++23
- Expanded constexpr Capabilities in C++23
- consteval and Compile-Time Function Execution
- std::source_location: Better Diagnostics at Compile Time
- Template Metaprogramming Patterns with C++23
- Performance Implications of Compile-Time Computation
- Key Takeaways
- Exercises
- Challenge Project
Chapter 8: Concurrency and Parallelism Improvements
- Concurrency in C++20: A Quick Recap
- New Synchronization Features
- Memory Model Improvements
- Parallel Algorithms Enhancements
- jthread and stop_token Improvements
- Thread Safety Best Practices and Pitfalls
- Key Takeaways
- Exercises
- Challenge Project
Chapter 9: Containers, Iterators, and Algorithms
- Container Improvements in C++23
- New Containers: flat_map and flat_set
- Iterators and Algorithms Enhancements
- Performance Characteristics
- Migration Strategies
- Key Takeaways
- Exercises
- Challenge Project
Chapter 10: Modules, Templates, and the Type System
- The Module System: Status and Best Practices in C++23
- Template Constraints and Concepts Refinements
- New Type Traits for Modern Programming
- Auto Parameter Deduction in Templates
- Impact on Build Times and Compilation Strategy
- Migration Strategies from Header-Based Libraries
- Key Takeaways
- Exercises
- Challenge Project
Chapter 11: Testing, Debugging, and Tooling
- Testing Strategies for Modern C++ Code
- Debugging Techniques: constexpr, Templates, and More
- Static Analysis Tools and C++23 Support
- Profiling and Benchmarking Modern C++
- IDE Support and Language Server Improvements
- Continuous Integration and Deployment with C++23
- Key Takeaways
- Exercises
- Challenge Project
Chapter 12: Production Patterns and Best Practices
- Design Patterns with Modern C++ Features
- Error Handling Strategies: expected, Exceptions, or Both?
- Performance Optimization Techniques
- Code Organization and Architecture Decisions
- Migration Strategies for Large Codebases
- What’s Coming Next: C++26 Preview
- Key Takeaways
- Exercises
- Challenge Project
- References
Conclusion: The Journey Continues
References
Appendix A: C++23 Feature Reference
Language Features
Library Features
- New Headers
- Key Library Additions
- Range Adaptors
- Range Algorithms
- String Improvements
- Other Library Features
Appendix B: Compiler Compatibility Matrix
Minimum Version Requirements
Feature Completeness by Compiler Version
- GCC
- Clang
- MSVC
Compiler Flags
Appendix C: Migration Checklist
Pre-Migration Assessment
Language Feature Migration
Library Feature Migration
- Error Handling
- Formatted Output
- Ranges
- Containers
- Compile-Time Programming
