Boost logo

Boost :

Subject: Re: [boost] Adding polymorphic_value to boost
From: Thorsten Ottosen (tottosen_at_[hidden])
Date: 2017-11-23 17:15:03


Den 23-11-2017 kl. 17:32 skrev Jonathan Coe via Boost:
>
>
>> On 23 Nov 2017, at 15:24, Thorsten Ottosen via Boost <boost_at_[hidden]> wrote:
>>

>> That's going to use way too much space, make swap/move slow and possibly noexcept(false), give poor reference stability. For that case of not heap-allocating each object in isolation, boost::poly_collection seems much better. So I would stick to the allocate on the heap approach.
>>
>
> One can limit the size of the buffer to make it tolerable (like std::function does) and only use the buffer for types than are noexcept-moveable. Reference stability is not a big concern to me (given the intended uses of the api) but is probably worth documenting.
>
> My proposed addition does not have a small object optimisation but I would not wish to rule out adding one.

That certainly should be documented. If one stores a base* somewhere
outside the collection, this is quite important to know if one should
dare sorting a collection of such objects.

And if we use a small buffer optimization, then we get the peculiar case
that reference stability depends on the size of the object.

polymorphic_value will leak the pointer abstraction anyway, so I don't
see any point in trying to disguise that.

Some other naming ideas:

   poly_value<T>
   base_value<T>
   poly_any<T>
   any<T>

kind regards

Thorsten


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