Boost logo

Boost :

From: Matthew Towler (towler_at_[hidden])
Date: 2003-04-24 10:37:31

> For a while I have been toying with the idea of a smart pointer called
> sortable_ptr, which would behave in the way that [I believe that] the
> original poster erroneously presumed that boost::shared_ptr already
> did. I was originally planning to do some more practical testing of
> the concept before possibly submitting it as a proposal to Boost, but
> since the topic has now been raised, I will take the opportunity to
> get some feedback as to whether the idea is sound, or if I have missed
> something crucial.
> The following is an extract from the draft documentation I have been
> writing.
> The class sortable_ptr is publicly derived from boost::shared_ptr, but
> defines the comparison operator < (and its siblings >, <=, and >= ) to
> make a comparison of the actual objects. This means that if the class
> myclass has operator< defined, we can write
> The == and != operators retain the semantics that they inherited from
> boost::shared_ptr, which is to test the pointers themselves for
> identity. This means that even if neither aptr < bptr nor aptr > bptr
> is true for two sortable_ptr pointers, the expression aptr == bptr may
> or may not be true.

I can see users getting confused by the fact that == and != compare the
pointers (so you can use them in loops), but the other operators compare
the objects.

I can also see a problem in that some objects will define just < and
your pointer will need to derive all the others from it, whereas others
will define the whole set, and your pointer should forward to them. I
am not sure there is a way of simply coding "implement it like this if
the function exists, otherwise do it like that".

Therefore I think this is a bad idea


Boost list run by bdawes at, gregod at, cpdaniel at, john at