Boost logo

Boost :

From: Gavin Lambert (boost_at_[hidden])
Date: 2020-01-29 04:11:28


Mere moments ago, quoth I:
> On 25/01/2020 01:21, Glen Fernandes wrote:
>> Heap storage, fixed size at runtime:
>>     allocate_unique<T[]>(alloc, size, ...)
>>
>>   Gives users everything they need for buffers. (They don't need a
>> Container that is copyable).
>
> Not quite.  These keep the storage pointer and the storage size
> separately, so you still need a wrapper type (such as the Asio buffer
> types), or to keep passing them around separately (which is error-prone)
> or to make assumptions instead of passing it around (which is very
> error-prone).
>
> C++20 introduces std::span, which is a good way of passing around a
> pointer and size together -- but it's non-owning, so still isn't a
> solution for the above.

To clarify: the Asio buffer types are also non-owning.

The need for an owning wrapper type is presumably what:

On 24/01/2020 21:44, Alexander Grund wrote:
> - Heap storage, fixed size at runtime: dynamic_array

was referring to (a type that contains a unique_ptr<T[]> and its size,
or equivalent thereof), thus can act as an owning container. (And you
can then extract a span or Asio buffer from this, to then pass around
without transferring ownership, or move the original container to
transfer ownership.)

Though I'm not familiar with any existing standard/Boost implementation
of this. It probably is a thing that ought to exist.

(But that's a terrible name for a container that cannot change size.)


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