From: Maxim Egorushkin (e-maxim_at_[hidden])
Date: 2003-10-23 08:01:05
Michael Grundberg wrote:
MG> In other words, we do:
MG> // Our resource
MG> int i;
MG> // Give it to the library
MG> boost::shared_ptr<int> p1(&i, null_deleter());
MG> std::set<boost::shared_ptr<int> > s; s.insert(p1);
MG> // A bit later
MG> boost::shared_ptr<int> p2(&i, null_deleter());
MG> Which doesn't remove the pointer from s. This is causing us alot of
MG> bugs, since the compilations succeed but the code is broken.
Looks like you are misusing shared_ptr<>.
The key point is that shared_ptr<> is an exclusive owner of a raw pointer. No more then one shared_ptr<> should be constructed using the same raw pointer (unless it is 0 pointer). Violating the rule leads to multiple releases on the raw pointer. Using null_deleter allows you to remain unpunished :).
So, as a unique raw pointer has the only associated shared_counters, operator<() can be implemented using not a raw pointer but its shared_counters.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk