← Previous · All Episodes · Next →
Mastering Type Erasure in C++23 A Macro-Free Approach for Cleaner Code Episode

Mastering Type Erasure in C++23 A Macro-Free Approach for Cleaner Code

· 01:39

|

Antoine Morrier's article discusses a method for implementing type erasure in C++ without the use of macros, addressing criticisms of macro usage in programming. He presents a C++23-compliant solution that utilizes features such as deducing this, along with structuring a lightweight and flexible type erasure system that allows for the definition of actions (like drawing) associated with different types (such as circles). The article details the design of a MethodTrait to retrieve function signatures, hold function pointers, and properly invoke them. It highlights a dual storage pattern for the concrete type and function pointers, promoting a cleaner and more efficient coding experience while aiming for future optimizations.

Key Points:

  • Objective: Implement C++ type erasure without macros, while improving code clarity.
  • C++23 Features: Utilizes deducing this for more flexible function signatures.
  • MethodTrait Structure: Facilitates the retrieval of method signatures and pointers; uses template specialization.
  • Erased Class: Inherits from action methods, supports function pointer storage and object storage via std::any.
  • Invoker Implementation: Allows calling methods based on their type using compile-time computations to select function pointers.
  • Future Plans: Articles planned on optimizations, performance enhancements, and alternatives to std::any.
    Link to Article

Subscribe

Listen to jawbreaker.io using one of many popular podcasting apps or directories.

← Previous · All Episodes · Next →