[eigen] const-correctness in Eigen 3.0

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


I've been following the occasional discussions regarding the const-incorrectness of Map (and Block, Transpose, etc.) with interest; I once put a lot of effort into getting this right in my own template-based multidimensional array library, and I'd love to see this get fixed in Eigen.

I'd be happy to put some effort into fixing this in Eigen 3.0, but as a relatively new face (well, I've been lurking a long time!) tackling a fairly widely-dispersed issue, I wanted to get some discussion going instead of just going out and making a giant patch.

First off, here's what I think the solution should look like:

- Matrix and Array (and other PlainObjectBase subclasses) should pretty much behave as they do currently.

- Map, Block, Transpose, and anything else that does not own its data but supports direct access should come in both const and non-const versions (probably just partial specializations). The non-const version should be implicitly convertible to the const version.

- Calling block() or transpose() on a const reference to Matrix should return a const Block or const Transpose(), etc.

What I think this implies:

- MatrixBase, ArrayBase, DenseBase, DenseCoeffsBase, and EigenBase should also have partial specializations for const and non-const; the non-const version should probably inherit from the const version in some cases for code reuse, just adding non-const accessors and augmented assignment operators.

 - PlainObjectBase should inherit from a non-const base class.

- Expressions that don't have direct access should inherit from the const MatrixBase or ArrayBase.

 - There should probably be a flag for constness on every Eigen class.


I anticipate these changes would be fairly straightforward, but they are very extensive. I don't seen any easier way to get const-correctness in place in a consistent way, however, and I think doing it now will pay off in the long run.

Any thoughts?

Jim Bosch



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/