|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-08-17 07:27:21
From: "Darin Adler" <darin_at_[hidden]>
> On Thursday, August 16, 2001, at 05:07 PM, Scott McCaskill wrote:
>
> > 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.
>
> shared_ptr already has a specialization of std::less that accomplishes
> this. Some have made a good argument for using an operator < rather than
> std::less, but others like the current implementation. (I'll dig up the
> relevant messages in the Boost archives if you want me too.)
Here is my summary (from shared_ptr.hpp):
//
// Namespace std:: definitions removed (Peter Dimov)
//
// Rationale:
//
// std::swap() overloads are illegal (17.4.3.1/1, LWG issue #226)
//
// std::less<> specializations that do not call operator< are illegal
// (17.4.3.1/1, 20.3.3/5)
//
// std::less cannot be partially specialized on compilers that do not
// support the feature
//
// std::less specializations do not help in cases like
// map<pair<shared_ptr, int>, int>
//
I should also add that std::swap() is already fast and non-throwing for
shared_ptr, so breaking 17.4.3.1/1 is not worth it.
> Given the current implementation, you should be able to use shared_ptr in
> a set. Have you tried it?
Not on a compiler that doesn't support partial specializations.
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk