Boost logo

Boost :

From: Greg Colvin (gcolvin_at_[hidden])
Date: 2001-08-16 19:45:37


From: "Scott McCaskill" <scott_at_[hidden]>
> I'd like to propose a minor addition to smart_ptr.hpp: operator<() for
> comparing two shared_ptrs. Without such an operator, it's not possible to
> use shared_ptr in certain STL containers (such as set) without defining
> one's own predicate.
>
> Although certainly not a show-stopper, it does seem odd that one is required
> to do this when operator==() and operator!=() do exist. Therefore, I think
> it seems reasonable, consistent and useful to add operator<(). Comments?
>
> // identical to existing operator==() except that '==' is replaced by '<'
> template<typename T, typename U>
> inline bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b)
> { return a.get() < b.get(); }

We've been around the block on this a few times now. As I recall I
argued that for raw pointers operator< is defined only for pointers
into the same object, which should never happen for shared_ptr. For
comparing arbitrary raw pointer you should use std::less, which we
have provided. But this choice seems to be causing enough confusion
and inconvenience that I no longer object to adding operator<.

Since others might still object, and since there are related defect
reports being resolved, and since shared_ptr may be presented to
the committee soon, I think it is time to gather up the various
suggestions for improvements and plan on a formal review of the
possible changes.


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