|
Boost : |
Subject: Re: [boost] Adding polymorphic_value to boost
From: Jonathan Coe (jonathanbcoe_at_[hidden])
Date: 2017-11-23 16:32:26
> On 23 Nov 2017, at 15:24, Thorsten Ottosen via Boost <boost_at_[hidden]> wrote:
>
>> Den 23-11-2017 kl. 00:31 skrev Phil Endecott via Boost:
>>
>> There's another way of implementing this, though; rather than
>> pointing to the object in the heap you can store it in-place
>> by allocating enough space for the largest possible derived
>> subclass:
>
> [snip]
>
>> That's just a sketch; many details omitted! There are some obvious
>> advantages and disadvantages of each approach and I'm definitely not
>> saying this is better than the pointer-to-heap design.
>
> 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.
>
> kind regards
>
> -Thorsten
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk