How can I preserve the order of elements within an unordered set after using insert (or emplace) without allocating during construction?
For details into this problem, here's an example:
- An unordered set S of integers is constructed
- 480 is inserted into S: S = { 480 }
- 32 is inserted into S: S = { 32 480 }
- 23 is inserted into S: S = { 23 32 480 }
- 16 is inserted into S: S = { 16 23 32 480 }
- 19 is inserted into S: S = { 19 480 32 23 16 }
You can see how the last insertion destroys the sequence order (I assume by reconstructing a larger set and moving the elements over). I'm looking for a way to preserve the previous order after inserting an element without the need for specifically allocating in the constructor.
420 69 1 2 420
then should the position of occurrence of420
be 1 or 5? – Dwinnell