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
Matt
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost