Eigen has introduced the Ref<> class to write functions with Eigen objects as parameters without the use unnecessary temporaries, when writing template functions is not w
In general, using a non const reference like Ref
is never a good idea because this will only work if the caller already has a Ref
object at hand. This discards 5 and 7.
The cases 3 and 4 does not make sense, and they won't compile in general.
Then, there is not much difference between a const Ref
and a const Ref
because it is unlikely that the function is called with an existing Ref
object, and so a Ref
will have to be created in most cases anyway. Nevertheless, we could still recommend 1 over 2 or 6.
So in summary, we could recommend Ref
for a writable reference, and const Ref
for a const reference.
The option 6, Ref
, might still be interesting if you want to change the matrix that is referenced (not its content) through a call to Ref
constructor using placement new.