From: Greg Colvin (gcolvin_at_[hidden])
Date: 2001-08-23 10:59:36


----- Original Message -----
From: Kevlin Henney <kevlin_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, August 23, 2001 12:33 AM
Subject: [boost] Re: Re: Re: Re: shared_ptr comparison

> > From: John Max Skaller <skaller_at_[hidden]>
> >
> > Doing so means the answer is: "replace that C array
> >with array<T>, and use smart_ptr< array<T> >", rather than
> >"use array_ptr<T>" no matter what it is named.
>
> Greg has already pointed out the existing boost::array template, which
> was one of the first submissions to Boost. It is a fixed-size array, so
> although it addresses the common concerns of actual declared C arrays,
> it does not address the new T[] issue, which is closer in spirit to
> vector than array -- scoped_ptr< array<T, N> > is actually not that
> useful when compared to scoped_array<T>.
>
> On a point of usage, scoped_array<T> is also not the moral equivalent to
> scoped_ptr< array<T, N> > or scoped_ptr< vector<T> >: the usage is at a
> different level of indirection, so it is not a comparison of like for
> like.

Here are the currently available usages:

   boost::scoped_ptr<T> p = new T;
   boost::scoped_array<T> p = new T[n];
   std::auto_ptr<T> p = new T;
   boost::shared_ptr<T> p = new T;
   boost::shared_array<T> p = new T[n];

The following can of course be used as T above:

   std::vector
   boost::array

There is really no use I can see for scoped_ptr<array<T>> or
scoped_ptr<vector<T>>. Shared_ptr is useful, but requires a
clumsy indirection in use. So perhaps we could provide a
new container

    boost::shared_vector<T> p = new vector<T,n>;
    boost::shared_vector<T> p = new array<T,N>;

with appropriate operator[] and forwarding members for other
vector functions. This would reduce the need for scoped_array
and shared_array. Perhaps instead of shared_vector we can
specialize shared_array for array<T,N>* ?

I also wonder if the core language could change so that the
type of new T[n] is pointer to array of T instead of pointer
to T. It seems that this change could prevent misuse of the
scoped_array and shared_array templates, but perhaps it will
fall afoul of the automatic decay of array types to pointers.