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.
Name | Description |
---|---|
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.
Name | Description |
---|---|
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. |
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.
Name | Category | Description |
---|---|---|
map➹ | Ordered | A lookup table with no duplicates |
multimap➹ | Ordered | A lookup table with duplicates |
set➹ | Ordered | A set of unique elements |
multiset➹ | Ordered | A set of non unique elements |
unordered_map➹ | Unordered | A lookup table with no duplicates |
unordered_multimap➹ | Unordered | A lookup table with duplicates |
unordered_set➹ | Unordered | A set of unique elements |
unordered_multiset➹ | Unordered | A 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