Re: problems with std::array
This is a multi-part message in MIME format...
------------=_1285306780-67546-11
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
On 24 Sep., 03:10, Chris Uzdavinis <cuz...@gmail.com> wrote:
On Sep 23, 8:18 am, Stefan van Kessel <stefan.van.kes...@mytum.de>
wrote:
...
If you need something that will be available in C++0x you could go with
something like:
std::shared_ptr<T> sp(new T[3], [](T* p){delete[] p;});
or
std::unique_ptr<T, std::function<void(T*)> >
up(new T[3], [](T* p){delete[] p;});
But that still doesn't allow you to use operator[]; instead you'd have
to do something like:
sp.get()[0] = foo;
or
(&*sp)[0] = bar;
I think it's both more susceptible to errors and less readable than
using [scoped/shared]_array.
unique_ptr has a partial specialization for array types already built
in,
so it's far easier than you are suggesting.
Note what Stefan was actually writing: He was complaining
about the reduced capabilities of std::shared_ptr and *not* about
those of std::unique_ptr.
std::unique_ptr<T[]> up( new T[3] );
up[0] = 999; // this is ok
Note: unique_ptr does provide operator[] for arrays.
See =A7 20.9.10.3 of the draft
standard:http://www.open-std.org/jtc1/sc22=
/wg21/docs/papers/2010/n3126.pdf
I understood Stefan, that he was aware of that.
Greetings from Bremen,
Daniel Kr=FCgler
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
------------=_1285306780-67546-11--