Ref<> (similar to Map) has the disadvantage that once initialized its reference can't be changed (without a placement-new hack). This is similar to C++ references.
An idea is to add the analogon of a pointer, which can be uninitialized (a NULL pointer) or which can be re-initialized at any time.
For reinitialization operator=(const DenseBase<...>&) can be overloaded.
Alternatively, we could overload operator& for DirectAccess types to return a Ptr object.
Ptr<MatrixXd> A = & M.block(...); // with overloaded operator&
Ptr<MatrixXd> A = M.block(...); // without overloading
But overloading & is very often causing trouble.
For fixed sized Ptr<> objects, initialization by a Scalar* could be considered:
Ptr<Matrix3d> B = data;
To access the referenced data, operator* and operator-> can be overloaded. Furthermore, operator! and operator bool can be overloaded to check if the pointer is NULL or not.
Overloading operator& is indeed not good practice. The following:
A = M.block(...);
through overloading Ptr::operator= would be confusing too. It is like the user forgotten something:
*A = M.block(...);
A = Ptr<>(M.block(...));
So I would rather enforce ctor calls.
(In reply to Gael Guennebaud from comment #1)
> A = Ptr<>(M.block(...));
That is less error-prone, indeed.
Perhaps a static Eigen::ptr function would be good, to avoid having to re-type the template parameters every time.
Ptr<MatrixXd, Stride<...> > A(X.block(...));
A = ptr(Y.block(...));
And we could add some kind of reInit(...) function, which accepts everything the constructor accepts: