I am currently experimenting on some usage of stl-datastructures. However I am still not sure when to use which one and when to use a certain combination. Currently I am trying
A map of vectors comes with the memory overhead for the capacity of each vector. std::vector
typically allocates space for more elements than you actually have. It may not be a big deal for your application, but it's another tradeoff you haven't considered.
If you're doing a lot of reads, then the O(1) lookup time of unordered_multimap
might be a better choice.
If you have a reasonably modern compiler (and given the presence of the auto
keyword, you do) then in general you're going to have a difficult time beating the standard containers in terms of performance and reliability. The people who wrote them are experts. I would always start with the standard container that most easily expresses what you want to do. Profile your code early and often, and if it's not running fast enough, then look for ways to improve it (e.g., using the unordered_
containers when doing mostly reads).
So, to answer your original question, if you need an associative array of values where those values won't be unique, then using std::multimap
definitely makes sense.