Taking Static Type-Safety to the Next Level - Physical Units for Matrices - Daniel Withopf CppCon 22

Discover how adding physical units to vectors and matrices can enhance type-safety, prevent invalid operations, infer units, create expressive names, detect errors, and more. Explore the power of physical units in C++.

Key takeaways
  1. Physical units can be added to vectors and matrices. This allows you to represent quantities like velocity and acceleration in a way that is both mathematically correct and easy to understand.
  2. Physical units can be used to prevent invalid operations. For example, you can’t add a velocity vector to a position vector, because the units don’t match up.
  3. Physical units can be used to infer the units of the result of an operation. For example, if you add two velocity vectors, the result will have units of velocity.
  4. Physical units can be used to create expressive and enforced names for vector and matrix entries. This makes it easier to understand what the code is doing and to avoid errors.
  5. Physical units can be used to detect dangling references and aliasing. This helps to prevent bugs that can be difficult to find.
  6. Physical units can be used to prevent out-of-bounds accesses. This helps to prevent undefined behavior and crashes.
  7. Physical units can be used to represent non-uniform vectors and matrices. This allows you to represent quantities that vary in different directions or over time.
  8. Physical units can be used to create a taxonomy of all different types of vectors and matrices. This makes it easier to understand the relationships between different types and to choose the right type for a given task.
  9. Physical units can be used to represent transformations between different coordinate frames. This allows you to translate and rotate vectors and matrices in a way that is both mathematically correct and easy to understand.
  10. Physical units can be used to represent Jacobians and other derivatives. This allows you to represent the relationship between the input and output of a function in a way that is both mathematically correct and easy to understand.