Possible Duplicate:
A std::map that kee开发者_开发百科p track of the order of insertion?
I am looking for an STL container that preserves order of insertion ( no sorting ) but does not allow duplicates. Is there one? if not any tricks I can use to customize one?
There is no such a container at the moment, but you can create your own one in a cheap way by holding a std::vector
and a std::set
in a class together.
I know you have specifically asked for an STL container however boost already provides a multindex container which does what you want with its ordered_unique index. I definitely worths looking at instead of reinventing the wheel.
I just wanted to point a good alternative.
Good luck.
No need to re-invent the wheel, consider using a boost::multi_index
container. You can then define various indexes to your heart's content. The performance difference (if you are worried) should be minimal.
There isn't one. Detecting duplicates without sorting or hashing is a pretty expensive operation.
精彩评论