c++ - how does the stl's multimap insert respect orderings? -
I have some data that comes with integer indices. I am constantly creating new data that gives me the data Need to add to the collection, which is sorted according to that index, at the same time I want to be able to easily start data and go through it again. It seems that Stud :: Multimap only what I want
However, I need the data with the same index in the order in which it was inserted, in this case, in this case it means that when I repeat data through the data before the next I get the data.
Do you do so?
I have not got any guarantee that this is the case. In the SGI manual, I did not mention whether I tried to implement it on GCC 4.3.4 and it proved to be true for some limited test cases, but definitely I was wondering if the standard demands it And I can trust this fact.
Edit: To be clear in response to some replies, I want the data to be sorted by the first (non-unique) index and second from the inclusion time. I expected that maybe the second part came in free with the multimap, but it seems that it is not so.
Unless I miss something, standard does not guarantee such a guarantee.
The most obvious solution is to include a sequence number as a secondary key. For example, your class includes a static unsigned long time, and every time you enter the value If you make an object, then put your current value in your object, and increase it. Use your counter as the deciding factor to use that counter in the comparing function, if you compare the data currently being used as a key. Note that in this case, each key will be unique, so that you can use the map instead of multimap.
Comments
Post a Comment