Given this set of toy structs:
struct foo {
virtual void print() { cout << "foo"; }
};
struct bar : foo {
virtual void print() { cout << "bar"; }
};
I would like to create a map
which:
- Has values which are polymorphic
- Has values which are non-const
- Is constructed via
initalizer_list
- Constructs the values within it's
initializer_list
- Is not initialized using secondary functions/lambdas/macros to convert the
initializer_list
into amap
- Does not require a separate cleanup function
Thus I can't figure out how to make any of these specializations of map
work:
map<int, foo*>
map<int, unique_ptr<foo>>
map<int, foo&>
map<int, foo&&>
The only thing that I have found which will work is map<int, shared_ptr<foo>>
. I'm unhappy with this because I don't want to allow shared ownership of the values. But it sounds like this is my only option?