Boost logo

Boost :

From: Schoenborn, Oliver (Oliver.Schoenborn_at_[hidden])
Date: 2003-04-25 08:43:29


> -----Original Message-----
> From: Daniel Frey [mailto:daniel.frey_at_[hidden]]
> Sent: Thursday, April 24, 2003 12:02 PM
> To: boost_at_[hidden]
> Subject: [boost] Re: Sorting list < shared_ptr < foo > > using
> std::list::sort()
>
>
> Heath Davis wrote:
> > Bravo!!! This is a truly novel approach! I agree that the
> > shared_ptr::operator< is meaningless. If boost wishes to claim STL
>
> I disagree strongly. A smart pointer is an as-transparent-as-possible
> replacement for a pointer, not a replacement for the object! What you
> are thinking about is a smart reference or something like that. Smart
> pointers behave like pointers and this is what your problem was.

I.e., the OP needs a proxy class for dynamically allocated objects (or as
close to is as you can get in C++). I've been toying with the idea of moving
away from pointers completely (i.e. as much as having to interact with
legacy libraries etc permits), and have created a small proxy library, where
it makes sense to provide sorting the way the OP suggested. With some simple
template techniques, it even works in an STL container, without using
dynamic memory (an otherwise very messy problem). This is still
experimental, but take a look at http://noptrlib.sourceforge.net.

> As Dave showed, a simple
>
> my_list.sort( *_1 < *_2 );
>
> is all you need to provide the correct sorting - that's not asked for
> too much, is it? :)

No, except that you have to incorporate a huge library of stuff unrelated to
sorting, just to do sorting.

> A vote to keep the smart pointer
> semantics as they are.

I agree.

Oliver


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