Move constructor for Ref<T const>
Describe the feature you would like to be implemented.
Ref<T const>
defines a copy constructor that does not copy its member variable m_object. The according comment says that this is "to avoid unnecessary malloc and copy". However, I do not see a reason for not defining a move constructor that moves m_object if EIGEN_HAS_RVALUE_REFERENCES is 1.
Would such a feature be useful for other users? Why?
Ref<T const>
defines m_object to optionally map its own data. However, this mapping may fail (e.g. due to unsuitable strides), in which case Ref<T const>::data()
returns nullptr, providing a way to check this failure state. But since C++ does not guarantee named return value optimization, checking this failure state is impossible in a function that shall return the Ref without moving it or making a copy. Making a copy is not an option due to Ref's unusual copy constructor, anyway. And creating another instance just for returning it after a successful check may be very costly. The only efficient solution would be to move it, but that requires the definition of a move constructor.
Any hints on how to implement the requested feature?
#ifdef EIGEN_HAS_RVALUE_REFERENCES
Ref(Ref&& other) : Base(other), m_object(std::move(other.m_object)) {}
#endif