开发者

STL Container that preserves order of insertion but allows no duplicates [duplicate]

This question already has answers here: Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜