What I need is a key-value container for keeping some well-known parameters of objects. All possible keys are known on compile time. Values are belong to differnt types: POD (integers, pointers) and non-POD (some small structures with contructors).
Current implementation uses very big structure and tons of code to initialize, fill and copy values. So I want to replace this structure with container. Container must provide: 1) quick access by key (constant time). 2) the possibility to iterate over all values to copy them.
I tried to think up some array based approach, but coldn't make it. I can make some hash table, but I don't know what to do with different value types.
sounds like std::unordered_map
(or boost::unordered_map
) is the right solution. Just use boost::any
for the objects so they can be any type.
You might want to look at Boost.Variant for storing the values. Then you can just use a std::map<Key, boost::variant>
or std::unordered_map<Key, boost::variant>
for your container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With