Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix C: Core Guidelines index

This appendix lists the C++ Core Guidelines rules referenced in the book, grouped by the chapter that teaches each rule. Rule IDs correspond to the CppCoreGuidelines version used during writing. When a rule appears in the text, its identifier is shown as (CG ) for easy lookup.

Chapter 2: values and functions

  • F.15: prefer simple and conventional ways of passing information.
  • F.20: for out-parameters, prefer return values over out-parameters.
  • F.21: to return multiple values, prefer returning a struct or tuple.
  • ES.25: declare an object const or constexpr unless you need to change its value.

Chapter 3: user-defined types

  • C.20: if you can avoid defining default operations, do.
  • C.2: use class if the class has an invariant.
  • C.2: use struct if the data members can vary independently.

Chapter 4: control flow

  • ES.28: use lambdas for complex initialization, especially of const variables.
  • ES.70: prefer a range-for-statement or a standard-library algorithm over a hand-written loop.

Chapter 5: ownership, move, and RAII

  • R.1: manage resources automatically using RAII.
  • R.3: a raw pointer or reference is never a resource owner.
  • R.10-R.11: avoid calling new and delete explicitly.

Chapter 6: smart pointers

  • R.20: use unique_ptr or shared_ptr to represent ownership.
  • R.22: use shared_ptr only to share ownership.

Chapter 7: lifetimes

  • Lifetime profile: never dereference a possibly-invalid pointer or iterator.
  • Lifetime profile: a pointer or reference to a local must not escape.

Chapter 8: argument passing

  • F.15: prefer simple and conventional ways of passing information.
  • F.20: for out-parameters, prefer return values over out-parameters.
  • F.21: to return multiple values, prefer returning a struct or tuple.
  • F.16-F.17: pass by value for small/cheap-to-move, const T& for big inputs.

Chapter 9: errors and contracts

  • E.1-E.16: error-handling rules, including throw when the function cannot do its job, and prefer std::expected for anticipated absence.
  • E.25: a function that cannot throw must be declared noexcept.

Chapter 11: containers

  • SL.con: standard-library container rules.
  • SL.con: prefer std::vector by default.

Chapter 12: algorithms

  • ES.70: prefer a range-for-statement or a standard-library algorithm over a hand-written loop.

Chapter 14: callables and type erasure

  • F.51-F.52: prefer a lambda or a function object for small callables.
  • F.51-F.52: prefer a regular function for a stateless callable.

Chapter 16-17: templates and concepts

  • T.1-T.65: template and generic-programming rules.
  • T.1-T.65: define concepts to express template constraints (T.10).

Chapter 21: reading legacy TMP

  • The rules for reading, not writing: write concepts, read SFINAE (T.1, T.10).

Chapters 25-26: concurrency

  • CP.1-CP.8: concurrency rules.
  • CP.1-CP.8: protect shared mutable state with a mutex or an atomic.
  • CP.1-CP.8: never access a non-atomic shared object without synchronization.

Chapter 29: fast is a specification

  • Perf.1-Perf.11: performance rules.
  • Perf.1-Perf.11: measure before optimizing (Perf.1).
  • Perf.1-Perf.11: avoid cheap micro-optimizations that do not show up in measurement.

This index is not exhaustive. The chapters cite the exact rule at the point of use. The intent of the book is that every rule it teaches is attributed, so a reader can chase the source of any guideline.