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.
You might want to look at Boost.Variant for storing the values. Then you can just use a
std::map<Key, boost::variant>orstd::unordered_map<Key, boost::variant>for your container.