Boost logo

Boost :

From: John Max Skaller (skaller_at_[hidden])
Date: 2001-08-20 15:46:13


Howard Hinnant wrote:
>
> And what about scoped_array?
>
> One of the biggest reasons I see a need for scoped_array (not so much
> for shared_array) is the ability to transfer ownership of the
> buffer. ... Ironically, now that I look more closely at scoped_array, I
> don't see any move semantics. :-)
>
> Ok, what I see a need for is an array version of auto_ptr (under
> whatever name) so that I can do something like:

        I admit I have some problems with the auto_ptr design:
the concept of 'move' is fine, but the lack of suitable C++
syntax is a pain. Since I tend to avoid such designs
(I never use auto_ptr), I don't have much experience with them.

        In general you could use:

        auto_ptr< array<T> >

but obviously that won't retrofit to legacy code, as in your
example. (you can't have your first class cake
and (tr)eat it second class too)

        In some ways, the best thing to do with such
code is to throw it out.

> struct LegacyBase
> {
> char* a1;
> char* a2;
> bool owns:
>
> LegacyBase() : a1(0), a2(0), owns(false) {}
>
> virtual ~LegacyBase()
> {
> if (owns)
> {
> delete [] a1;
> delete [] a2;
> }
> }
> };
>
> struct MyClass
> : public LegacyBase
> {
> MyClass()
> {
> auto_ptr<char[]> r1(new char [256]);
> auto_ptr<char[]> r2(new char [256]);
> a1 = r1.release();
> a2 = r2.release();
> owns = true;
> }
> };
>
> -Howard
>
> On Sunday, August 19, 2001, at 02:59 PM, John Max Skaller wrote:
>
> > My main contention is that
> >
> > a) we should drop shared_array
> > b) we should use
> >
> > shared_ptr< array<T> >
> > shared_ptr< fixed_array<T,n> >
> >
> > instead of
> >
> > shared_ptr< T[] >
> > shared_ptr< T[n] >
> >
> > That is: don't specialise shared_ptr. Instead, make
> > first class array types for fixed length arrays
> > of both the types (1) length constant known at compile
> > time and (2) length constant bound at construction time.
> > [And use vector for (3) length variable]
> >
> > The reason is:
> >
> > 1) the first class types have uses
> > other than shared objects
> >
> > 2) there is no need to specialise shared_ptr
> > for such first class types
> >
> > I.e.: I agree with removing shared_array and using shared_ptr,
> > but suggest that instead of a specialisation, to use first class
> > array types.
>
> Info: http://www.boost.org Unsubscribe: <mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

-- 
John (Max) Skaller, mailto:skaller_at_[hidden] 
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
New generation programming language Felix  http://felix.sourceforge.net
Literate Programming tool Interscript     
http://Interscript.sourceforge.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk