Hi, Jonathan Wakely wrote:
On 8 July 2013 09:22, Sid Sacek wrote:
If you want a container, use one. Containers with shared storage would be a nice addition to Boost, IMHO, but these should not abuse shared_ptr interface.
According to what you just wrote 'shared_ptr
' has already abused 'shared_ptr<>' and all of the array features should be rolled back, or be put into another class altogether. I disagree with your implication that shared_ptr
abuses anything, maybe your view is skewed by thinking it's trying to be something it isn't. shared_ptr<T> and shared_ptr are similar to T* pointing to a single object, and a T* pointing to an array, with the same limitation that the size is not part of the pointer but with the advantage that you don't have to remember whether to use delete or delete[]. Now you could argue that using pointers to refer to arrays abuses pointers, but that's how C++ works, and it does have many advantages.
And correct me if I'm wrong but as with using operator-> with a pointer to array, there is also possible to use operator[] with a pointer to non-array variable: T *a = new T[1]; T *v = new T; a->m; v->m; a[0].m; v[0].m; Boost's smart pointers implements a reasonable subset of those operations which reflects: v->m = 0; a[0].m = 0; There are no additional methods in pointers, indicating the size of allocated storage. Smart pointers should probably be as close as possible to the raw ones because they are pointers not containers or buffers. Regards, Adam