@Elpezmuerto: Your other question (which has been reopened) is also looking for use cases. You even say in the question: "I am looking for general use cases for each containers."
–
eldarerathisOct 24 '10 at 20:06

1

That was edited to try to get it to be reopened. It was closed as not a real question and clearly it is a real question as shown by the answers provided here. Tomasz has shown that was his answer and I got what I was looking for.
–
ElpezmuertoOct 24 '10 at 20:24

4

Please don't close this question. A few others not looking at its content would come along seen deleting it and Tomasz' very nice overview would be lost.
–
sbiOct 24 '10 at 20:41

2 Answers
2

It's available from nolyc, the informative bot of ##C++ on Freenode, using the command "container choice" or "containerchoice". The link to this picture you receive in response is hosted at adrinael.net, which suggests we should thank Adrinael, member of Freenode's ##C++ community.

list - linked list. This container is not memory-continuous. Its time for adding and deleting elements is O(1), but looking for a specific element is O(n). Unordered container.

map - container, stores pairs (std::pair). The first one is the key - every element from the map must be with unique key. The map is represented as tree, so the searching for an element in the map is n*log(n). This container is always sorted, that's why adding and removing elements could cause more time - the tree(the data structure) is binary and balanced.

multimap - almost the same as std::map, but allows pairs with the same keys. For example, a multimap could contain elements: (666, "alabala"), (666, "asdfg"), while the standard std::map can't. This container is also sorted.

multiset - again - the same as set, but with repeatable elements. set - well, this is also always sorted STL container. For example, a set is { 1, 2, 3 } and when you try to add '1' into this set, it will not be added, as already there's such element. (it's analogical to the mathematical's set). So, multiset allows several elements with the same value, for example { 1, 1, 1, 2, 3, 4, 4, 4, 4 } is a correct multiset, while it's not a set. Adding and removing element into std::set is still logarithmic time, as it's represented as a binary, sorted and balanced tree.

priority_queue - its first element is always the greatest of the elements it contains, according to some strict weak ordering condition. Basic functionality - push_back and pop_back.

queue - FIFO structure - First in, first out. (or the same as LILO - Last In - Last Out). It's analogue to a standard queue - when you go to a shop and start waiting on the queue, the first one there will be the first one to go. You can just push_back and pop_front. Unordered container.