Containers

Overview
STL provides a host of template based containers serving as arrays and lookups to store and retrieve any data type.

Details
They can be broadly classified as below.

sequence containers
These containers  store data sequentially using different mechanisms.

NameDescription
vector➹A single ended variable size array.
vector<bool>➹A specialization of vector. Compactly stores bool values.
list➹A doubly-linked list.
forward_list➹A singly-linked list.
deque➹A double ended queue with random access.
array➹A fixed size array.

container adapters
Container adapters provide specialized functionality and are based on a sequence container.

NameDescription
priority_queue➹Items are stored as determined by a comparison function. 
queue➹Items are stored in LIFO (Last In First Out) order.
stack➹Items are stored in FIFO (First In First Out) order.

associative containers
These are basically lookup tables that store key value pairs. They can be classified into two categories - ordered and unordered.  The ordered category containers are implemented using balanced binary trees whereas the the unordered category containers are implemented using hash tables. 
Also the ordered containers accept comparison function and the elements are sorted accordingly whereas the unordered containers accept a hash function and equality function and the elements are stored accordingly.

NameCategoryDescription
map➹OrderedA lookup table with no duplicates
multimap➹OrderedA lookup table with duplicates
set➹OrderedA set of unique elements
multiset➹OrderedA set of  non unique elements
unordered_map➹UnorderedA lookup table with no duplicates
unordered_multimap➹UnorderedA lookup table with duplicates
unordered_set➹UnorderedA set of unique elements
unordered_multiset➹UnorderedA set of  non unique elements

emplacement functions➹

STL containers such as vector, list, map to provide pushxxx and insert functions to add new elements. Most of these functions end up creating a temporary object of the type T of the container. In C++ 11,  a new emplace functions were that would accept added to directly construct the object of type T in the container.


No comments:

Post a Comment