Jonathan Coe wrote:
On 20 Nov 2017, at 16:57, Peter Dimov via Boost
wrote:
Looking at my old code, what I did was supply both a cloning pointer
(U*) and a polymorphic value (U&&) types, the latter a simple wrapper
over the former.
This was my original design too which was strongly opposed by LEWG.
Looking at P0201R0, R1, R2, you only propose one class though. In R0, you
propose cloned_ptr, and in R1/R2, a value class. So you get value proponent
criticisms on R0 and pointer proponent criticisms on R2.
What I am suggesting is two classes.
template<class T> class cloning_ptr
{
public:
template
explicit cloning_ptr( U*, C = C{}, D = D{} );
};
template<class T> class polymorphic_value
{
private:
cloning_ptr<T> p_;
public:
template
polymorphic_value(U&& u, C c = C{}, D d = D{} ):
p_( c(forward<U>(u)), move(c), move(d) )
};
(+add T&& overload to default_copy.)
Two classes instead of one is not without its downsides, since they are very
similar in both appearance in behavior, but on the plus side, this allows us
to make the interface of the pointer class unapologetically pointer-like and
the interface of the value class... well, as value-not-pointer-like as
possible, which isn't much due to op->, but still. :-)