C++ Core Guidelines Explained: Best Practices for Modern C++

Book description

Write More Elegant C++ Programs

“We are very pleased to see Rainer Grimm applying his teaching skills and industrial background to tackling the hard and necessary task of making the C++ Core Guidelines accessible to more people.”

—Bjarne Stroustrup and Herb Sutter, co-editors, C++ Core Guidelines

The official C++ Core Guidelines provide consistent best practices for writing outstanding modern C++ code and improving legacy code, but they’re organized as a reference for looking up one specific point at a time, not as a tutorial for working developers. In C++ Core Guidelines Explained, expert C++ instructor Rainer Grimm has distilled them to their essence, removing esoterica, sharing new insights and context, and presenting well-tested examples from his own training courses.

Grimm helps experienced C++ programmers use the Core Guidelines with any recent version of the language, from C++11 onward. Most of his code examples are written for C++17, with added coverage of newer versions and C++20 wherever appropriate, and references to the official C++ Core Guidelines online.

Whether you’re creating new software or improving legacy code, Grimm will help you get more value from the Core Guidelines’ most useful rules, as you write code that’s safer, clearer, more efficient, and easier to maintain.

  • Apply the guidelines and underlying programming philosophy

  • Correctly use interfaces, functions, classes, enum, resources, expressions, and statements

  • Optimize performance, implement concurrency and parallelism, and handle errors

  • Work effectively with constants, immutability, templates, generics, and metaprogramming

  • Improve your C++ style, manage source files, and use the Standard Library

Register your book for convenient access to downloads, updates, and/or corrections as they become available. See inside book for details.

Table of contents

  1. Cover Page
  2. About This eBook
  3. Halftitle Page
  4. Title Page
  5. Copyright Page
  6. Pearson’s Commitment to Diversity, Equity, and Inclusion
  7. Contents
  8. List of selected C++ Core Guidelines
  9. List of figures
  10. List of tables
  11. Foreword
  12. Preface
    1. Conventions
    2. Why guidelines?
    3. Panta rhei
    4. How to read this book
  13. Acknowledgments
  14. About the author
  15. Part I: The Guidelines
    1. Chapter 1. Introduction
      1. Target readership
      2. Aim
      3. Non-aims
      4. Enforcement
      5. Structure
      6. Major sections
    2. Chapter 2. Philosophy
    3. Chapter 3. Interfaces
      1. The curse of non-const global variables
      2. Dependency injection as a cure
      3. Making good interfaces
      4. Related rules
    4. Chapter 4. Functions
      1. Function definitions
      2. Parameter passing: in and out
      3. Parameter passing: ownership semantics
      4. Value return semantics
      5. Other functions
      6. Related rules
    5. Chapter 5. Classes and Class Hierarchies
      1. Summary rules
      2. Concrete types
      3. Constructors, assignments, and destructors
      4. Class hierarchies
      5. Overloading and overloaded operators
      6. Unions
      7. Related rules
    6. Chapter 6. Enumerations
      1. General Rules
      2. Related rules
    7. Chapter 7. Resource Management
      1. General rules
      2. Allocation and deallocation
      3. Smart pointers
      4. Related rules
    8. Chapter 8. Expressions and Statements
      1. General
      2. Declarations
      3. Expressions
      4. Statements
      5. Arithmetic
      6. Related rules
    9. Chapter 9. Performance
      1. Wrong optimizations
      2. Wrong assumptions
      3. Enable optimization
      4. Related rules
    10. Chapter 10. Concurrency
      1. General guidelines
      2. Concurrency
      3. Parallelism
      4. Message passing
      5. Lock-free programming
      6. Related rules
    11. Chapter 11. Error Handling
      1. Design
      2. Implementation
      3. If you can’t throw
      4. Related rules
    12. Chapter 12. Constants and Immutability
      1. Use const
      2. Use constexpr
    13. Chapter 13. Templates and Generic Programming
      1. Use
      2. Interfaces
      3. Definition
      4. Hierarchies
      5. Variadic templates
      6. Metaprogramming
      7. Other rules
      8. Related rules
    14. Chapter 14. C-Style Programming
      1. Entire source code available
      2. Entire source code not available
    15. Chapter 15. Source Files
      1. Interface and implementation files
      2. Namespaces
    16. Chapter 16. The Standard Library
      1. Containers
      2. Text
      3. Input and output
      4. Related rules
  16. Part II: Supporting Sections
    1. Chapter 17. Architectural Ideas
    2. Chapter 18. Nonrules and Myths
    3. Chapter 19. Profiles
      1. Pro.typeType safety
      2. Pro.boundsBounds safety
      3. Pro.lifetimeLifetime safety
    4. Chapter 20. Guidelines Support Library
      1. Views
      2. Ownership pointers
      3. Assertions
      4. Utilities
  17. Part III: Appendixes
    1. Appendix A. Enforcing the C++ Core Guidelines
      1. Visual Studio
      2. clang-tidy
    2. Appendix B. Concepts
    3. Appendix C. Contracts
  18. Index
  19. Code Snippets

Product information

  • Title: C++ Core Guidelines Explained: Best Practices for Modern C++
  • Author(s): Rainer Grimm
  • Release date: April 2022
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 9780136875758