Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2001-05-24 10:09:07


> --- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> > I have some comments on shared_ptr.
> >
> > 1. Isn't specializing std::less without defining the corresponding
operator<
> > setting a dangerous precedent? This means that sort(f, l) and sort(f, l,
> > less<>()) could potentially give different results.
>
> Sometimes it's valid to have less<type> but not operator<(type,
> type). Not that this is such a case, but it makes it less likely
> that a "dangerous precedent" is being set.
>
> Since the standard defines full relational operations for pointer
> types, however, I'd agree that shared_ptr could benefit from them.

The Standard only defines full relational operations for pointer types
*pointing into the same array*. And if you have two shared_ptr's pointing
into the same array, you've got a lot more to worry about than operator< :).

So, comparision operators really don't fit with shared_ptr.

Having said that, the reason std::less is provided is to allow shared_ptr's
to be used as keys for maps. Again, shared_ptr reflects the Standard here,
which defines std::less for *all* pointers (not just pointing into the same
array).

As you pointed out, sort(..) can be screwed up, but only by a truly
brain-dead co-worker who defines operator< to be something different than
std::less...

So I think it makes sense as is.

        -Steve


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