Boost logo

Boost :

From: Glen Fernandes (glen.fernandes_at_[hidden])
Date: 2020-01-29 05:39:01


I wrote:
>
> On Wed, Jan 29, 2020 at 12:27 AM Gavin Lambert via Boost wrote:
>
> > https://www.boost.org/doc/libs/1_72_0/libs/smart_ptr/doc/html/smart_ptr.html#allocate_unique
> >
> > claims that it returns a std::unique_ptr<T[], D>.
>
> Correct.
>
> A std::unique_ptr<T[], D> stores a D::pointer.
>
> In our case, D is alloc_deleter<T[], A> and its ::pointer is an
> alloc_ptr<T[], Allocator>.
>
> This alloc_ptr<T[], Allocator> stores an A::pointer and a size_t.
>
> > This seems incompatible with what you're saying above.
>
> It isn't.
>
> > (There is also no mention of ptr() or size() there.)
>
> It specifies that the ::pointer is an 'unspecified' pointer-like type.
> I forgot to document that on this unspecified pointer type one can use
> .ptr() to get the Allocator::pointer and .size() to get the size.
>

Basically, a unique_ptr result from an allocate_unique<T[]>(a, n)
_has_ to store the n somewhere in the unique_ptr because it needs to
know how many objects to destroy and what size storage to deallocate.

I also provide access for you to get that n. (I just forgot to put it
in the documentation).

Glen


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