|
Boost : |
Subject: Re: [boost] shared_ptr<X[5]>
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2012-11-05 22:38:14
On Mon, Nov 5, 2012 at 6:37 AM, Peter Dimov <lists_at_[hidden]> wrote:
> Now that we (are going to) have shared_ptr<X[]>, what should
> shared_ptr<X[5]> do?
>
>> From user point of view, it seems obvious that this is as good a pointer
>> to
>
> an array as shared_ptr<X[]> is, so it should behave similarly, having op[]
> and an element_type of X.
>
>> From a generic point of view, this could potentially break code that
>> assumes
>
> that shared_ptr<T>::get() always returns a T*, even when T is X[5]. But how
> common is such a scenario?
I think it's reasonable that the generic code assume anything returned
by shared_ptr<T>::get be a pointer -- even if it required decay in
the constructor.
I'd suggest that any such generic code would be responsible for
reversing any potential pointer decay, if it was really necessary.
Otherwise they may just need to use element_type* (or auto, if they're
fortunate).
>
> On the other hand, it will actually _fix_ generic code of the form
>
> shared_ptr<T> p( new T );
>
> when T is X[5].
While both seem unlikely, the latter seems more likely than the former. . .
Nate
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk