I would like to use the Eigen matrix library as the linear algebra engine in my program. Eigen uses expression templates to implement lazy evaluation and to simplify loops a
Why would exposing data_
break encapsulation? Encapsulation means hiding the implementation details and only exposing the interface. If your wrapper class UsingEigen
does not add any behavior or state to the native Eigen
library, the interface does not change. In this case, you should drop this wrapper altogether and write your program using the Eigen
data structures.
Exposing a matrix or a vector is not breaking encapsulation: only exposing the implementation of the matrix or vector would do that. The Eigen
library exposes the arithmetic operators but not their implementation.
With expression template libraries, the most common way for users to extend the library functionality is by adding behavior, not adding by adding state. And for adding behavior you do not need to write wrapper classes: you can also add non-member functions that are implemented in terms of the Eigen
class member functions. See this column "How Non-Member Functions Improve Encapsulation" by Scott Meyers.
As for your concern that the transformation of your current program to a version that explicitly uses the Eigen
functionality: you can perform the change step-by-step, changing small parts of your program each time, making sure your unit tests (you do have unit tests, don't you?) do not break as you go along.