Boost logo

Boost :

Subject: Re: [boost] Adding polymorphic_value to boost
From: Peter Dimov (lists_at_[hidden])
Date: 2017-11-20 17:59:48


Jonathan Coe wrote:

> > On 20 Nov 2017, at 16:57, Peter Dimov via Boost <boost_at_[hidden]>
> > 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<class U, class C = ..., class D = ...>
    explicit cloning_ptr( U*, C = C{}, D = D{} );
};

template<class T> class polymorphic_value
{
private:

    cloning_ptr<T> p_;

public:

    template<class U, class C = ..., class D = ...>
    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. :-)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk