Boost logo

Boost :

Subject: Re: [boost] [shared_array] Why not in C++11 ?
From: Peter Dimov (lists_at_[hidden])
Date: 2013-07-08 11:54:03

Rob Stewart wrote:

> That's error-prone. Why not provide (non-zero) capacity when using
> make_shared(), and leave the non-make_shared() usage with a zero capacity?

That's not very convenient. Suppose you get a T* from some place and need to
pass shared_ptr<T[]> to another that requires a known size. You know the
size, but you won't be able to pass it.

It's also error prone. If you have an interface that takes shared_ptr<T[]>
and size_t, you can tell that the code is passing a size by mere visual
inspection. But if the function only takes a shared_ptr<T[]>, and if
shared_ptr<T[]> might or might not have a size, it's not immediately obvious
whether you are passing a size or not. Maybe you are, maybe you aren't;
we'll have to wait until runtime and see.

Finally, zero is technically a legitimate value for the size, signifying an
empty array, so overloading it to denote "unknown" may not be the best

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