|
Boost : |
Subject: Re: [boost] Adding polymorphic_value to boost
From: Peter Dimov (lists_at_[hidden])
Date: 2017-11-20 16:57:36
Jonathan Coe wrote:
> The pointer constructor is needed in migration paths from class
> heirarchies with a `Clone()` method. It also allows one to support objects
> coming from C_APIs.
Supporting
X* create(...);
X* copy( X const* );
void destroy( X* );
is appropriate for a cloning pointer, but hasn't really much to do with
polymorphic values.
struct Shape
{
virtual ~Shape() = default;
Shape* clone() const = 0;
void draw() = 0;
};
Shape* createCircle( int r );
is admittedly less clear-cut.
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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk