Glen Fernandes wrote:
I can see why you desire this. One concern is that boost::shared_ptr
is usable without boost::make_shared. With boost::make_shared, yes, in my implementation the size is stored somewhere and changing the machinery could possibly surface that through boost::shared_ptr's interface. But what happens when boost::shared_ptr is used with operator new[]? The size is not stored in that case. You mentioned in an earlier mail that you would prefer that size() return a value like -1 in such a case. That also feels very strange to me; i.e. returning a size_t but reserving a value like -1 to indicate unknown size.
Glen
My original idea to return -1 was not very good. Zero is much better.
I'm new to 'shared_ptr< T[] >'; I don't know how long it's been out there and being
used in production code, but if all the rules for shared_ptr< T[] > have not yet
been set in stone, then maybe there's room for modifications.
My original thought was to make 'size' a requirement for shared_ptr< T[] > since why
would anyone use an array without knowing the array's bounds ? Every array has bounds
and nobody would touch an array without knowing that information. And placing that
information with the array itself makes the most sense to me.
If it were made a requirement, then the code might look something like this, or
something even more clever:
shared_ptr< char[] > buffer( new char[ 10 ], 10 );
The above constructor would set the capacity value to 10. If however, the coder were
to simply do this:
shared_ptr< char[] > buffer( new char[ 10 ] );
It is clear that the coder has no interest in the capacity information for the buffer,
and therefore no other part of that programmer's code will be looking for it either.
This would be a non-breaking change, since that is the default behavior of shared_ptr