Boost logo

Boost :

Subject: Re: [boost] Rationale for shared_ptr/array including both ptr to control and ptr to data in class
From: Peter Dimov (pdimov_at_[hidden])
Date: 2011-09-26 09:20:40

Olaf van der Spek wrote:
> Ah. BTW, why doesn't shared_array provide size()?
> IMO it'd be quite useful to have.

The obvious answer, that it doesn't have this information, has already been
given, but it's not enough; you could legitimately ask why shared_array
doesn't have it, that is, why its constructor doesn't take a size in
addition to the pointer.

The answer is, well, historical reasons. While the current shared_ptr allows
you to easily implement a sized shared_array by storing the size in a
deleter, when shared_array was first designed, this was not the case.
shared_array was kept a simple reference-counted wrapper over new T[].
shared_ptr then evolved considerably, and shared_array has failed to keep
up. So here we are. :-)

Boost list run by bdawes at, gregod at, cpdaniel at, john at