Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-05-24 12:39:52

----- Original Message -----
From: "Gary Powell" <Gary.Powell_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, May 24, 2001 1:07 PM
Subject: RE: [boost] Re: Smart pointer status, directions, thoughts

> > 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).
> >
> Actually having used that feature, a map with keys as smart pointers, I
> found that it didn't work, and I had to write a helper class which would
> force the map to evaluate the contents of the smart pointers as the keys.
> (Also if you do this (use shared pointers as keys), for me its fine for
> insertion, but sucks for lookup, because you have to create a new smart
> pointer if the key doesn't come from some other container of said smart
> pointers. I ended up tossing it as it became an ugly mess of helper
> allocations etc. The size savings wasn't worth the runtime penalty.
> So I would actually prefer that shared pointers NOT have std::less<>
> defined.
> 1) because it rarely makes sense to compare two pointers for a map.
> 2) The lack of the overload would force the programmer to decide what they
> actually wanted instead of the silent compile and generally wrong result.

I disagree. Smart pointers have a coherent notion of identity and can be
strict-weak ordered. It sounds like you didn't carefully consider what it
means to compare them (although it's not complicated - it generally means
the same as pointer comparison), and ended up with the wrong result. I don't
think the rest of us should be penalized for that.


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