Boost logo

Boost :

From: Maxim Yegorushkin (e-maxim_at_[hidden])
Date: 2004-02-03 13:24:06

Brian McNamara wrote:

> On Mon, Feb 02, 2004 at 11:50:45PM -0800, Rich Sposato wrote:
>> The containers are called flex_set, flex_map, flex_multiset, and
>> flex_multimap. They are similar to the 4 STL associative containers.
>> There are two important differences between the STL containers and these:
>> 1. You can search on any type that is comparable to the key_type, rather
>> than just the key_type. (The STL associative containers only allows
>> searches on the same type as the key.)
>> 2. You do *not* need to create a temporary object of key_type to search
>> through the containers. (The STL containers require you to create one
>> temporary object to search for another.)
> A good idea. I recall wishing for something like this a while ago; I
> don't remember if it stemmed from an actual problem in practice or just
> general unhappiness with the std:: interface in theory.

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.

Maxim Yegorushkin
MetaCommunications Engineering

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