Does the C++ standard library have an \"ordered set\" datastructure? By ordered set, I mean something that is exactly the same as the ordinary std::set
but that
No, it does not.
Such a container presumably would need two different iterators, one to iterate in the order defined by the order of adding, and another to iterate in the usual set
order. There's nothing of that kind in the standard libraries.
One option to simulate it is to have a set
of some type that contains an intrusive linked list node in addition to the actual data you care about. After adding an element to the set
, append it to the linked list. Before removing an element from the set
, remove it from the linked list. This is guaranteed to be OK, since pointers to set elements aren't invalidated by any operation other than removing that element.