Is there a unique container such like std::list with simple functionality (push,pop,clear, etc.) and not sorted order unlike std::set, or maybe I need to extend std::list and add my own push_unique method )) ?
1 Answer
The STL is supposed to provide efficient containers.
A container which does not allow duplicates needs to support fast lookup to determine whether the value you want to is already present in the collection or not.
std::set keeps the item sorted in a red-black tree, which is what allows an O(log(n)) lookup, insertion, and removal.
std::unsorted_set allows constant-time lookup, insertion, and removal, but you need to provide a hash function for most UDT types, you need to take care of issues such as rehashing, which cause iterator invalidation, and you do not have any defined order for your items (not even the insertion order).
If you want to use a simple collection such as std::vector without allowing duplicates, you need to provide your own adapter.
However, I still can't figure out why you have problems with a sorted container such as std::set if, as you say, the order doesn't matter for you.
std::(tr1::)unordered_set.