P0847 proposes the possibility of using explicit this parameter for member functions.
Among other great goodies that this proposal brings, there is also the great new possibility for CRTP without C, R and even T.
A common practice for implementing a generic clone in C++ is based on CRTP, see for example this SO post.
Given that we need clone to be virtual (or at least, behave as virtual), to allow:
Shape* pCopy = pShape->clone(); // get a copy of the correct runtime type
And given that the proposal is that a member function with an explicit this parameter shall not be declared virtual.
Would there still be a way to use P0847 in order to implement a generic clone with dynamic behavior and without CRTP?
template deduction only uses static type, whereas
Cloneneed dynamic type, and sovirtual.P0847 mostly allows to transform
into
What you could do though is simplify the covariance with smart pointer.
But CRTP seems better as it allows to avoid to rewrite
do_clonefor each type.(future reflection might simplify
Clonable)