Boost logo

Boost :

Subject: Re: [boost] Adding polymorphic_value to boost
From: Peter Dimov (lists_at_[hidden])
Date: 2017-11-21 15:56:49


Mathias Gaunard wrote:
> On 21 November 2017 at 10:50, Jonathan Coe <jonathanbcoe_at_[hidden]> wrote:
>
> >
> > Thanks Matthias,
> >
> > Is there a way we can search the archives for the old discussion?
...
>
> Here are a few I've found
>
> https://lists.boost.org/Archives/boost/2000/03/2696.php (2000)
> https://lists.boost.org/Archives/boost/2007/09/126982.php (2007)
> https://lists.boost.org/Archives/boost/2010/05/166647.php (2010)

The earliest deep-copy pointer is Alan Griffiths's grin_ptr:

http://web.archive.org/web/20110907102434/http://www.octopull.demon.co.uk/arglib/TheGrin.html

It's "grin_ptr" because Pimpl was known as Chesire's Cat in those days for
some reason.

My own impl_ptr from 2001 can be found here:

http://pdimov.com/cpp2/impl_ptr.zip

Again, impl_ptr because its primary purpose is to implement the Pimpl idiom,
but in that same archive there's a variant<T> class which is a polymorphic
value.

(Both Pimpl and polymorphic values need const propagation.)

A copying pointer has been re-proposed repeatedly, but it didn't take.
Polymorphic values also didn't become very popular, perhaps because in C++03
when you push_back one into a vector you pay dearly in reallocations. This
pushes one towards implementing copy-on-write, for which shared_ptr is
better suited, or often you're even fine with vector<shared_ptr> and
Javaesque code that only deep copies on an explicit copy() call.

Note that for such a type to be usable for Pimpl, it has to support
incomplete types. Meaning, you have to be able to copy and destroy
polymorphic_value<T> for incomplete T.

If you search for impl_ptr or grin_ptr, you'll find a number of old threads.
Or, if you find the `any` formal review thread, you'll see me going on and
on about something called ref<T>, which is like polymorphic_value<T>, bit
with == and <. (And making the point that `any` is a special case of that
for T=void.)

For performance-sensitive uses, instead of vector<poly_value<T>> we now have
base_collection<T> in poly_collection:

http://www.boost.org/doc/libs/1_65_1/doc/html/poly_collection.html

which is significantly more efficient.


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