Boost logo

Boost :

From: Rich Sposato (rds_at_[hidden])
Date: 2004-02-03 17:47:43

Maxim Yegorushkin wrote:
> I had difficulty storing and finding boost::intrusive_ptr<> in std::set<>.
> When I wanted to check if an arbitrary pointer value was in that set like:

> struct some {/*...*/};
> typedef boost::intrusive_ptr<some> some_ptr;
> typedef std::set<some_ptr> some_set;
> some_set set;

> bool exists(some const* s)
> {
> return set.find(s) != set.end();
> }
> void foo()
> {
> bool b = exists(reinterpret_cast<some*>(0xdeadbeaf)); // boom
> }

> as std::set::find() requires a key value, it ended up with constructing the
> smart pointer from a bogus value trying to do add_ref() and then release()
> on that value which led to runtime errors.

> If std::set<> had been able to use not a key value for find() but a key
> comparable value I would not have had any problems with that code.

I had similar problems with a conversion constructor getting invoked when I wanted to pass a pointer or value into std::set::find or std::multiset::count.

That was one of the dificulties which led me to create flex_set and its related classes. Since flex_set does not require a temporary object, it also does not silently invoke a conversion constructor.


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