Eigen Design
Writing notes to this, similar to the way I have ROS Design for ROS.
Eigen was designed to use CRTP to avoid inheritance and looking up Vtables.
Eigen’s class hierarchy is designed so that virtual functions are avoided where their overhead would significantly impair performance. Instead, Eigen achieves polymorphism with the CRTP.
- In this pattern, the base class (for instance,
MatrixBase
) is in fact a template class, and the derived class (for instance,Matrix
) inherits the base class with the derived class itself as a template argument (in this case,Matrix
inherits fromMatrixBase<Matrix>
). This allows Eigen to resolve the polymorphic function calls at compile time.
So essentially, Eigen is built smart to avoid unnecessary copy operations. Instead, the value is computed during the copy assignment
Why isn’t Eigen OOP?
Because the virtual tables add overhead. You need a lookup table.