[ptr_container] Abstract Key type in ptr_map<Key, Val> impossible?

Hello, The following code would not compile. struct Key { bool operator<(const Key&) const; virtual void blah() const = 0; }; struct Val { /* */ }; boost::ptr_map<Key, Val> map; Although boost::ptr_set<Key> set; seems to work.

AMDG Mikhail Levin wrote:
The following code would not compile.
struct Key { bool operator<(const Key&) const; virtual void blah() const = 0; };
struct Val { /* */ };
boost::ptr_map<Key, Val> map;
Although boost::ptr_set<Key> set; seems to work.
I believe that ptr_map stores the key be value. In Christ, Steven Watanabe

Steven Watanabe <watanabesj <at> gmail.com> writes:
I believe that ptr_map stores the key be value.
In Christ, Steven Watanabe
I see. Thank you. It would be good to document this prominently, because it is natural to expect that ptr_map<Key,Val> stores Key*, since "a set can be seen as a map, where values are irrelevant" and ptr_set<Key> stores Key*.

Mikhail Levin skrev:
Steven Watanabe <watanabesj <at> gmail.com> writes:
I believe that ptr_map stores the key be value.
In Christ, Steven Watanabe
I see. Thank you.
It would be good to document this prominently, because it is natural to expect that ptr_map<Key,Val> stores Key*, since "a set can be seen as a map, where values are irrelevant" and ptr_set<Key> stores Key*.
It should be somewhat clear from the examples, and other documentation. There are several options that you may employ: A) use shared_ptr<const Key> as key B) use std::map<shared_ptr<const Key>,value> -Thorsten
participants (3)
-
Mikhail Levin
-
Steven Watanabe
-
Thorsten Ottosen