Boost logo

Boost Users :

Subject: Re: [Boost-users] [ptr_container][ptr_map]
From: Thorsten Ottosen (tottosen_at_[hidden])
Date: 2014-09-22 04:42:33


On 13-09-2014 22:52, Aaron Levy wrote:
> Consider the following code:

>
> I can create a ptr_set of Base like this:
>
> boost::ptr_set<Base> set;
>
> But I can't create a ptr_map with Base as key, like this:
>
> boost::ptr_map<Base, Base> map;
>
> The problem is that Base is abstract and so the key cannot be instantiated by ptr_map. What is the cause for this distinction between ptr_set and ptr_map.
>

I guess it might be possible, but the work involved was probably large.
The workaround is

boost::ptr_map<boost::shared_ptr<const Base>,Base>

although it's probably not a great workaround, depending on what
semantics you are looking for. IIRC, the map interface was not really
easy to adopt for a key that is polymorphic.

regards

-Thorsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net