On 29/01/2020 18:39, Glen Fernandes wrote:
A std::unique_ptr
stores a D::pointer. In our case, D is alloc_deleter
and its ::pointer is an alloc_ptr . This alloc_ptr
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
(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).
Does it also implicitly decay to a T*? (I did have a look at https://github.com/boostorg/smart_ptr/blob/master/include/boost/smart_ptr/al... but I don't see any `operator T*`, which is what I'd expect.) If not, that seems like it'd make it hard to pass to something expecting a raw pointer (eg. as method argument, or to construct a std::span). Or unless you know about the extra undocumented .ptr() indirection requirement.