about
10/27/2022
C++ Story LibrarySTL
Chapter #11 - Standard Template Libraries (STL)
containers, iterators, algorithms and example code
11.0 Prologue
11.1 STL Libraries
11.2 Containers
Table 1. List of STL Containers
- Simple code demos for each containerContainer | Description |
---|---|
std::array<T,N> | Fixed size array residing entirely in the local stackframe. This is the only container, other than native arrays, that manages its data in the stack. All others place their data in the native heap. |
std::deque<T> | Indexable container with FIFO semantics constructed from three blocks of contiguous memory for fast access to the front and back. |
std::list<T> | doubly-linked list, iterable but not indexable, can be traversed in either direction. |
std::map<K,V> |
Balanced binary tree with associative lookup: |
std::multi_map<K,V> |
Same as |
T t[N] |
Native array is indexable and iterable with native |
std::priority_queue<T> | Heap structure that returns the largest of its elements. |
std::queue<T> |
An adapter, by default based on |
std::set<T> | Based on balanced binary tree, does not allow duplicate keys. |
std::multi_set<T> |
Same as |
std::singlelist<T> | Singly linked list, is iterable with forward iterator but not indexable. |
std::stack<T> |
An adapter, by default implemented using |
std::string<Char> | Has all of the attributes of the other containers, is iterable and indexable. |
std::unordered_map<K,V> | Hashed associative container with unique keys. Has a set of hash functions supplied by default for the primative types and strings. |
std::unordered_multimap<K,V> |
Same as |
std::unordered_set<K> | Hashed set with unique keys. |
std::unordered_multiset<K> |
Same as |
std::vector<T> | Expandable array that is iterable and indexable. |
11.3 Algorithms
Table 2. - Partial List of Algorithnms
- complete listAlgorithms | Description |
---|---|
applies operation to each element | |
checks if a predicate is true for all, any, or none of the elements | |
returns numver of elements satisfying predicate | |
finds first element satisfying a predicate | |
searches for any one of a set of elements | |
searches for a range of elements | |
copies a range of elements to a new location | |
moves a range of elements to a new location | |
copies value to every element in a range | |
applies operation to a range of elements, storing results in a destination range | |
applies results of operation to every element of a range | |
remove elements satisfying predicate | |
replaces all values satisfying predicate with new value | |
swaps two ranges of elements | |
reverses order of elements in range | |
rotates order of elements in range | |
shifts elements in a range | |
removes consecutive duplicates in range | |
divides elements of a range into two groups | |
sorts a range into ascending order | |
sorts a range of elements while preserving order of equal elements | |
merges two sorted ranges | |
returns largest or smallest element in range | |
determines if two ranges are equal | |
returns true if one range is alphabetically less than another | |
finds sum of a range of elements |
11.4 Examples
Example: Standard Uses
Example: Uses Range-Like Construct
11.5 Epilogue
11.6 References
C++ Networking TS draft
KissNet
Smart Output Iterators - Jonathan Boccara
Smart output iterators become pipes - Jonathan Boccara
C++ Seasoning (video) - Sean Parent - Going Native 2013
string formatting (see answer 15) - stackoverflow
KissNet
Smart Output Iterators - Jonathan Boccara
Smart output iterators become pipes - Jonathan Boccara
C++ Seasoning (video) - Sean Parent - Going Native 2013
string formatting (see answer 15) - stackoverflow