impulse impulse - 15 days ago 5
C++ Question

to store unsorted key value pair

Is there any container available in C++ STL to store unsorted key value pair with duplicate keys?

I was thinking std::unordered_multimap container will help me in this case but the elements with equivalent keys are grouped together in this.

Answer

I recommend you to look at sequence containers. Basically you can store std::pair< key, value > at some sequence container.

If you just need to store key-value pairs and sometimes add new key-value pair at the end of the container then std::vector is enough. If you additionally want to insert elements in the beginning of the container then look at std::deque. And so on...

So the best strategy is to analyze your constraints and choose the appropriate sequence container.

Comments