I have some data which come with a integer index. I am continuous generating new data which needs to added to the collection of data I have, sorted by that index, at the sa
It sounds like multimap is what you need...
However, I also need data with the same index to be kept in the order in which it was inserted, in this case meaning that when I iterate through the data I get to the earlier data before the later data.
It will be in the order of the index. If the index increases over time as you insert more items, then yes because of the nature of your index, the "earlier" data will come first.
Otherwise, no. You could keep two multimaps to the same data. One kept in order of index, the other in order of insertion time:
std::multimap orderedByIndex;
std::multimap
Giving you the ability to iterate the map both ways.
(Edit I'm reading this to mean you want to sometimes iterate by index or sometimes iterate by insertion time, but see the above answer if you mean first index then insertion time.)