SlideShare a Scribd company logo
1 of 202
Standard Template Library
Ilio Catallo - info@iliocatallo.it
Outline
β€’ Introduc*on
β€’ Ideals and concepts
β€’ Generic programming
β€’ Bibliography
Introduc)on
The Standard Template Library
The C++ Standard Library includes a set of algorithms and data
structures that were originally part of a third-party library, called
the Standard Template Library (STL)
The Standard Template
Library
The Standard Template Library was
invented by Alexander Stepanov in 1994
circa, and later included in the C++
Standard Library
The Standard Template
Library
The STL is the outcome of two decades of
Stepanov's effort in delinea8ng the
fundamental principles of programming
The Standard Template
Library
Before turning to C++, Stepanov
unsuccessfully tried implemen9ng the STL
using languages such as Scheme and Ada
An approach to computa-on
"The STL is unlike any other library you have seen before."
(S. T. Lavavej)
An approach to computa-on
"People look at STL and think it's a nice container and algorithm library.
It is not, it is a different way of thinking about code."
(S. Parent)
What makes the STL so special?
Storing and manipula/ng objects
Consider the problem of storing objects in containers and wri6ng
algorithms to manipulate such objects
Storing and manipula/ng objects
We want to be able to store objects of a variety of types in a
variety of containers and to apply a variety of algorithms
Storing and manipula/ng objects
Furthermore, we want the use of these objects, containers, and
algorithms to be:
β€’ Sta%cally type safe
β€’ As fast possible
β€’ As compact as possible
β€’ Not verbose and readable
Storing and manipula/ng objects
"Achieving all of this simultaneously isn't easy. In fact, I spent about 10
years unsuccessfully looking for a solu>on to this puzzle."
(B. Stroustrup)
List inser)on
In order to appreciate this, let us consider the problem of inser5ng
an arbitrary long sequence of progressive numbers into a list
List inser)on
We will see how to solve this problem using STL and Glib1
1
Glib is a general-purpose C library associated with the GNOME desktop environment. For more informaBon about
GLib, see hEps://developer.gnome.org/glib/stable/
STL: inser+on
std::list<int> l;
for (int i = 0; i < 10; i++) l.push_back(i);
Glib: inser+on
GList* list = NULL;
int* data_ptr;
for (int i = 0; i < 10; i++) {
data_ptr = g_new(int, 1);
*data_ptr = i;
list = g_list_append(list, (void*) data_ptr);
}
The NΒ·M problem
Before the STL, all the available general computa8on libraries
suffered from the NΒ·M problem
The NΒ·M problem
If you have N containers and M algorithms, you need NΒ·M different
implementa;ons in order to provide each algorithm for each
possible container
Glib: finding in a doubly-linked list
GList* list = ...;
GList* tmp;
int* data_ptr;
data_ptr = g_new(int, 1);
*data_ptr = 7;
tmp = g_list_find(list, (void*) data_ptr);
Glib: finding in a singly-linked list
GSList* list = ...;
GSList* tmp;
int* data_ptr;
data_ptr = g_new(int, 1);
*data_ptr = 7;
tmp = g_slist_find(list, (void*) data_ptr);
The STL solu+on
The STL solu+on is based on parameterizing containers with their
element types and on completely separa-ng the algorithms from
the containers
STL: finding in a doubly-linked list
std::list<int> l = {1, 10, 8, 7};
auto p = std::find(l.begin(), l.end(), 7);
STL: finding in a singly-linked list
std::forward_list<int> l = {1, 10, 8, 7};
auto p = std::find(l.begin(), l.end(), 7);
The STL is extensible
Since containers and algorithms are independent, introducing a
new container does not require reimplemen6ng all the available
algorithms
The STL is extensible
All available algorithms will simply work with the new container
Ideals and concepts
The STL components
The STL is composed of three main components, namely,
algorithms, iterators and containers
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ use β”‚ β”‚ expose β”‚ β”‚
β”‚ Algorithms │────────▢│ Iterators β”‚ ──────────│ Containers β”‚
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
The STL components
Moreover, func%on objects are used to customize both algorithms
and containers
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ use β”‚ β”‚ expose β”‚ β”‚
β”‚ Algorithms │─────────▢│ Iterators β”‚ ─────────│ Containers β”‚
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β–² β–²
β”‚ β”‚
β”‚ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ β”‚ β”‚
β”‚ customize β”‚ β”‚ customize β”‚
└────────────────────│ Function objects β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ β”‚
β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Algorithms
The swap func)on
We extensively discussed the proper.es of the swap func.on
swap alterna(ves
At first, we wrote several alterna*ves of the swap func0on, each
of which tailored for a specific built-in type
void swap(int& x, int& y) {
int tmp = x;
x = y;
y = tmp;
}
swap alterna(ves
At first, we wrote several alterna*ves of the swap func0on, each
of which tailored for a specific built-in type
void swap(double& x, double& y) {
double tmp = x;
x = y;
y = tmp;
}
swap alterna(ves
At first, we wrote several alterna*ves of the swap func0on, each
of which tailored for a specific built-in type
void swap(char& x, char& y) {
char tmp = x;
x = y;
y = tmp;
}
swap for built-in types
Later, we no+ced that we can devise a uniform implementa.on of
swap for any built-in type T
// T is a built-in type
void swap(T& x, T& y) {
T tmp = x;
x = y;
y = tmp;
}
swap for semi-regular types
Ul#mately, we observed that the very same implementa#on is s#ll
valid for any copy-construc+ble and assignable type
// T is copy-constructible and assignable
void swap(T& x, T& y) {
T tmp = x;
x = y;
y = tmp;
}
swap for semi-regular types
That is, the same implementa.on is valid for any semi-regular type
// T is semi-regular
void swap(T& x, T& y) {
T tmp = x;
x = y;
y = tmp;
}
Language limita,ons
Unsurprisingly, the following code does not compile
// T is semi-regular
void swap(T& x, T& y) {
T tmp = x;
x = y;
y = tmp;
}
Language limita,ons
Unsurprisingly, the following code does not compile
// void swap(T& x, T& y) {
// ^
// error: 'T' was not declared in this scope
Language limita,ons
This is because the compiler requires func4on parameters to be
exis%ng types
// T is semi-regular
void swap(T& x, T& y) {
T tmp = x;
x = y;
y = tmp;
}
Language limita,ons
Apparently, the language is limi&ng us in harnessing the underlying
regularity we were able to no5ce
// T is semi-regular
void swap(T& x, T& y) {
T tmp = x;
x = y;
y = tmp;
}
Func%on templates
To solve this, we will turn swap into a func%on template
Func%on templates
A func'on template defines a family of func,ons, rather than a
single func'on
swap as a func(on template
This allows us to define at once all the alterna1ve versions of swap
function template: swap(T&, T&)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ β”‚
β”‚ β€’ swap(double&, double&) β”‚
β”‚ β”‚
β”‚ β”‚
β”‚ β€’ swap(int&, int&) β”‚
β”‚ β”‚
β”‚ β”‚
β”‚ β€’ swap(char&, char&) β”‚
β”‚ β”‚
β”‚ β€’ swap(float&, float&) β”‚
β”‚ β”‚
β”‚ β”‚
β”‚ β”‚
β”‚ β€’ swap(vector_int&, vector_int&) β”‚
β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
swap as a func(on template
The defini)on of swap as a func)on template is as follows:
template <typename T> // T is semi-regular
void swap(T& x, T& y) {
T tmp = x;
x = y;
y = tmp;
}
Template instan,a,on
The func. template generates as many actual func1ons as needed
T = double β†’ swap(double&, double&)
Template instan,a,on
The func. template generates as many actual func1ons as needed
T = int β†’ swap(int&, int&)
Template instan,a,on
The func. template generates as many actual func1ons as needed
T = char β†’ swap(char&, char&)
Template instan,a,on
Func%on templates are instan%ated at compile-)me
template <typename T>
void swap(T& x, T& y) { ... }
int main() {
float f1 = 3.4, f2 = 7.3;
char c1 = 'a', c2 = 'b';
swap(f1, f2);
swap(c1, c2);
}
Template instan,a,on
Func%on templates are instan%ated at compile-)me
void swap(float& x, float& y) { ... }
void swap(char& x, char& y) { ... }
int main() {
float f1 = 3.4, f2 = 7.3;
char c1 = 'a', c2 = 'b';
swap(f1, f2);
swap(c1, c2);
}
std::swap
In fact, we derived the defini1on of std::swap as of C++03
template <typename T> // T is semi-regular
void swap(T& x, T& y) {
T tmp = x;
x = y;
y = tmp;
}
Iterators
The min_element algorithm
In a previous lecture, we devised an algorithm for finding the
minimum element of an integer array
The min_element algorithm
int* min_element(int* first, int* last) {
if (first == last) return last;
int* min = first;
++first;
while (first != last) {
if (*first < *min) min = first;
++first;
}
return min;
}
The min_element algorithm
It is immediate to see that the procedure does not depend on the
elements being integers
int* min_element(int* first, int* last) { ... }
The min_element algorithm
It is immediate to see that the procedure does not depend on the
elements being integers
double* min_element(double* first, double* last) { ... }
The min_element algorithm
It is immediate to see that the procedure does not depend on the
elements being integers
char* min_element(char* first, char* last) { ... }
The min_element algorithm
Hence, we can write min_element as a func%on template
template <typename I>
I min_element(I first, I last) { ... }
min_element as a func(on template
template <typename I>
I min_element(I first, I last) {
if (first == last) return last;
I min = first;
++first;
while (first != last) {
if (*first < *min) min = first;
++first;
}
return min;
}
Element type independence
We can now invoke min_element regardless of the element type
template <typename I>
I min_element(I first, I last) { ... }
Using min_element
template <typename I>
I min_element(I first, I last) { ... }
int main() {
double ds[] = {7.1, 2.3, 5.6, 9.0};
char cs[] = {'a', 'b', 'c'};
double* d = min_element(ds, ds + 4);
char* c = min_element(cs, cs + 3);
}
Using min_element
I is derived to be double* when passing an array of m elements of
type double
template <typename I>
I min_element(I first, I last) { ... }
Using min_element
I is derived to be char* when passing an array of m elements of
type char
template <typename I>
I min_element(I first, I last) { ... }
Can we use min_element on linked lists?
Finding the minimum
The algorithm for finding the minimum is independent of the way
we store elements in memory
β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬ ─ ┐
xs: β”‚ 1 β”‚ 7 β”‚13 β”‚ 5 β”‚
└───┴───┴───┴───┴ ─ β”˜
β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β”
xs: β”‚ 1 β”œβ”€β”€β”€ 7 β”œβ”€β”€β”€13 β”œβ”€β”€β”€ 5 │──▢ *
β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜
Finding the minimum
Because of this, we should be able to apply min_element on
linked lists as well
β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬ ─ ┐
xs: β”‚ 1 β”‚ 7 β”‚13 β”‚ 5 β”‚
└───┴───┴───┴───┴ ─ β”˜
β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β”
xs: β”‚ 1 β”œβ”€β”€β”€ 7 β”œβ”€β”€β”€13 β”œβ”€β”€β”€ 5 │──▢ *
β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜
Requirements on I
For min_element to work, we need some proper/es to hold for I
template <typename I>
I min_element(I first, I last) {
if (first == last) return last;
I min = first;
++first;
while (first != last) {
if (*first < *min) min = first;
++first;
}
return min;
}
Requirements on I
Namely, we require I to be:
β€’ Equality & inequality comparable
β€’ Copy construc6ble & assignable
β€’ Incrementable
Passing a pointer
For arrays, I is derived to be a pointer
template <typename I>
I min_element(I first, I last) { ... }
Passing a pointer
Since pointers sa-sfy the requirements we iden-fied, the algorithm
works
template <typename I>
I min_element(I first, I last) { ... }
Linked lists
However, intrusive linked lists are usually implemented as
struct node {
int value;
node* next;
};
Linked lists
Therefore, we need to subs0tute pointers with a user-defined type
that s0ll meets the requirements for I
template <typename I>
I min_element(I first, I last) { ... }
Iterators
We refer to such user-defined types as iterators
class list_iterator {
...
};
Linked list iterator
Namely, we will write a class named list_iterator to be used
in conjunc5on with the node class
class list_iterator {
...
};
list_iterator representa)on
class list_iterator {
public:
...
private:
???
};
list_iterator representa)on
class list_iterator {
public:
...
private:
node* curr;
};
list_iterator constructor
class list_iterator {
public:
list_iterator(???): ??? { ??? }
private:
node* curr;
};
list_iterator constructor
class list_iterator {
public:
list_iterator(node* curr): curr(curr) {}
private:
node* curr;
};
list_iterator default constructor
class list_iterator {
public:
list_iterator(node* curr): curr(curr) {}
list_iterator(): curr(nullptr) {}
private:
node* curr;
};
Dereference overload
class list_iterator {
public:
list_iterator(node* curr): curr(curr) {}
list_iterator(): curr(nullptr) {}
??? operator*() ??? { ??? }
private:
node* curr;
};
Dereference overload
class list_iterator {
public:
list_iterator(node* curr): curr(curr) {}
list_iterator(): curr(nullptr) {}
int& operator*() const { return curr->value; }
private:
node* curr;
};
Dereference constness
Note that operator* is always const, even for non-const
iterators
int& operator*() const { return curr->value; }
Dereference constness
Constness only means that the iterator cannot be later modified so
as to point to a different posi5on in the data structure
list_iterator const it1 = ...;
it1 = it2; // it1 cannot be re-assigned so as to point to a different location
Dereference constness
Nevertheless, it is perfectly valid to modify the data pointed to by a
constant iterator
list_iterator const it1 = ...;
*it1 = 10;
Dereference constness
Recall that we are trying to mimic pointers, and this is perfectly
aligned with the way pointers behave:
int a = 10, b = 7;
int* const p = &a;
p = &b; // error: p is a constant pointer
*p = 5; // legit: a is now 5
Prefix increment overload
class list_iterator {
public:
list_iterator(node* curr): curr(curr) {}
list_iterator(): curr(nullptr) {}
int& operator*() const { return curr->value; }
??? operator++() { ??? }
private:
node* curr;
};
Prefix increment overload
class list_iterator {
public:
list_iterator(node* curr): curr(curr) {}
list_iterator(): curr(nullptr) {}
int& operator*() const { return curr->value; }
list_iterator& operator++() { curr = curr->next;
return *this; }
private:
node* curr;
};
Equality overload
class list_iterator {
public:
list_iterator(node* curr): curr(curr) {}
list_iterator(): curr(nullptr) {}
int& operator*() const { return curr->value; }
list_iterator& operator++() { curr = curr->next;
return *this; }
bool operator==(list_iterator& y) const { ??? }
private:
node* curr;
};
Equality overload
class list_iterator {
public:
list_iterator(node* curr): curr(curr) {}
list_iterator(): curr(nullptr) {}
int& operator*() const { return curr->value; }
list_iterator& operator++() { curr = curr->next;
return *this; }
bool operator==(list_iterator& y) const { return curr == y.curr; }
private:
node* curr;
};
Inequality overload
class list_iterator {
public:
list_iterator(node* curr): curr(curr) {}
list_iterator(): curr(nullptr) {}
int& operator*() const { return curr->value; }
list_iterator& operator++() { curr = curr->next;
return *this; }
bool operator==(list_iterator& y) const { return curr == y.curr; }
bool operator!=(list_iterator& y) const { return !(*this == y); }
private:
node* curr;
};
list_iterator
list_iterator supports all opera+ons required by
min_element
template <typename I>
I min_element(I first, I last) { ... }
min_element
void print_min(node* head) {
list_iterator first(head);
list_iterator last;
list_iterator m = min_element(first, last);
if (m != last)
std::cout << "the min is " << *m;
}
Algorithms vs. containers
Note that min_element is completely unaware of the existence
of any container
template <typename I>
I min_element(I first, I last) { ... }
Algorithms vs. containers
As a ma&er of fact, min_element works as long as we provide a
type that meets the requirements for I
template <typename I>
I min_element(I first, I last) { ... }
Algorithms vs. containers
"The reason that data structures and algorithms can work together
seamlessly is... that they do not know anything about each other."
(A. Stepanov)
Iterators delimit sequences
An iterator allows abstrac/ng an arbitrary container as a sequence
of elements
β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬ ─ ┐
β”‚ 7 β”‚12 β”‚ 3 β”‚
└───┴───┴───┴ β”€β–²β”˜
β”‚
β”‚
β”‚
past-the-end
element
Iterators delimit sequences
This is true regardless of the fact that elements may in fact not be
con4guously allocated in memory (as with linked lists)
3rd past-the-end 1st 2nd
elem. elem. elem. elem.
──────▢ ───────▢ ───────▢ ───────▢
β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”
... β”‚ β”‚ β”‚///β”‚///β”‚ β”‚ β”‚///β”‚///β”‚ β”‚ β”‚ β”‚ β”‚///β”‚///β”‚ β”‚ β”‚///β”‚///β”‚ ...
β””β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”˜
──▢
1 byte
list_iterator vs. pointers
Note that list_iterator does not support all pointer
opera*ons
class list_iterator {
...
};
list_iterator vs. pointers
For instance, we cannot decrement a list_iterator
list_iterator it;
--it; // compile-time error;
Forward iterators
We refer to iterators such as list_iterator as forward
iterators
Random access iterators
A pointer – on the other hand – models a random access iterator,
which is the most feature-rich iterator possible
Iterator hierarchy
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Iterator β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β–²
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Input Iterator β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β–²
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Forward Iterator β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β–²
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Bidirectional Iterator β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β–²
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Random Access Iterator β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Requirements on I
Therefore, we can now refine the requirements on I
template <typename I>
I min_element(I first, I last) { ... }
Requirements on I
Namely, we require I to be a forward iterator
template <typename I>
I min_element(I first, I last) { ... }
Requirements on I
Namely, we require I to be a forward iterator
template <typename I> // I is a forward iterator
I min_element(I first, I last) { ... }
Requirements on I
Moreover, the type resul/ng from dereferencing the forward
iterator (i.e., its value type) should model a totally ordered type
// I is a forward iterator
// I's value type is a totally ordered type
template <typename I>
I min_element(I first, I last) { ... }
Top-down vs. bo-om-up
No#ce that we could not iden#fy the requirements without looking
at the implementa)on
// I is a forward iterator
// I's value type is a totally ordered type
template <typename I>
I min_element(I first, I last) { ... }
Top-down vs. bo-om-up
This is to say that – some-mes – we cannot determine the
interface in a top-down fashion
// I is a forward iterator
// I's value type is a totally ordered type
template <typename I>
I min_element(I first, I last) { ... }
Top-down vs. bo-om-up
Some%mes, we need to look at the implementa%on to determine
the interface
// I is a forward iterator
// I's value type is a totally ordered type
template <typename I>
I min_element(I first, I last) { ... }
Containers
vector_int
During previous classes, we were able to incrementally write a
simplified version of std::vector called vector_int
class vector_int {
...
};
vector_int
class vector_int {
public:
vector_int(): sz(0), elem(nullptr) {}
vector_int(std::size_t sz): sz(sz), elem(new int[sz]) {...}
vector_int(vector_int const& v): sz(v.sz), elem(new int[v.sz]) {...}
~vector_int() {...}
std::size_t size() const {...}
int operator[](std::size_t i) const {...}
int& operator[](std::size_t i) {...}
vector_int& operator=(vector_int const& v) {...}
bool operator<(vector_int const& v) const {...}
// definitions for !=, <, >=, <=
private:
std::size_t sz;
int* elem;
};
vector_int vs. algorithms
Unfortunately, vector_int cannot be used with any of the
algorithms we previously wrote (e.g., copy and min_element)
Algorithms expect iterators
As we just saw, algorithms that operate on a sequence expects a
pair of iterators, rather than the container per se
// I is a forward iterator
// I's value type is a totally ordered type
template <typename I>
I min_element(I first, I last) { ... }
vector_int vs. algorithms
To solve this, vector_int should be able to expose its own
iterators
begin() and end()
Namely, vector_int should provide two member func8ons
named begin() and end()2
2
And possible constant variants cbegin() and cend()
begin() and end()
begin() and end() should return an iterator to the first and to
the past-the-end element, respec2vely
β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬ ─ ┐
β”‚ 7 β”‚12 β”‚ 3 β”‚
└───┴───┴───┴ β”€β–²β”˜
β”‚
β”‚
β”‚
past-the-end
element
begin() and end()
Let us add begin() and end() to vector_int
class vector_int {
public:
...
??? begin() { ??? }
??? end() { ??? }
private:
std::size_t sz;
int* elem;
};
begin() and end()
Let us add begin() and end() to vector_int
class vector_int {
public:
...
int* begin() { return elem; }
int* end() { return elem + sz; }
private:
std::size_t sz;
int* elem;
};
Const begin() and end()
class vector_int {
public:
...
int* begin() { return elem; }
int* end() { return elem + sz; }
int const* begin() const {Β return elem; }
int const* end() const { return elem + sz; }
private:
std::size_t sz;
int* elem;
};
vector_int and min_element
template <typename I>
I min_element(I first, I last) { ... }
void print_min(vector_int v) {
int* first = v.begin();
int* last = v.end();
int* m = min_element(first, last);
if (m != last)
std::cout << "the min is " << *m;
}
vector_int and min_element
Although the code works, we s1ll have a issue
void print_min(vector_int v) {
int* first = v.begin();
int* last = v.end();
int* m = min_element(first, last);
if (m != last)
std::cout << "the min is " << *m;
}
vector_int and min_element
More precisely, we are revealing too much about the type of the
iterator
int* first = v.begin();
int* last = v.end();
vector_int and min_element
Users of vector_int should not be concerned with the fact that
iterators are either pointers or user-defined types
int* first = v.begin();
int* last = v.end();
Member type aliases
Thus, we will hide the actual type of the iterator through the use of
member type aliases (or simply member types)
Member type aliases
Member types are type aliases that are defined within the scope of
a class
Type aliases
int main() {
using integer = int;
integer a = 5; // the same as: int a = 5;
}
Member type aliases
class X {
public:
using integer = int;
};
int main() {
// the same as: int a = 5;
X::integer a = 5;
}
Iterator member types
Type aliases for iterators and const iterators are required to be
called, resp., iterator and const_iterator
class vector_int {
public
using iterator = ???
using const_iterator = ???
...
};
Iterator member types
Type aliases for iterators and const iterators are required to be
called, resp., iterator and const_iterator
class vector_int {
public
using iterator = int*;
using const_iterator = int const*;
...
};
Iterator member types
We consequently change the return type of begin() and end()
class vector_int {
public
using iterator = int*;
using const_iterator = int const*;
...
};
Iterator member types
class vector_int {
public:
using iterator = int*;
using const_iterator = int const*;
...
iterator begin() { return elem; }
iterator end() { return elem + sz; }
const_iterator begin() const {Β return elem; }
const_iterator end() const { return elem + sz; }
private:
std::size_t sz;
int* elem;
};
Random access iterator
No#ce that vector_int::iterator is a random access iterator
vector_int::iterator first = v.begin();
first = first + 2; // random access
std::vector's iterator type
Similarly, given a value of type std::vector<T>, the related
iterator type is std::vector<T>::iterator
std::vector<int> v = {7, 10, 5, 8};
std::vector<int>::iterator first = v.begin();
std::vector<int>::iterator last = v.end();
vector_double
It is immediate to see that the if we had to write vector_double,
its implementa3on would not differ from that of vector_int
class vector_double {
public:
...
private:
std::size_t sz;
double* elem;
};
Class template
As with algorithms, we can express such a similarity by turning
vector_int in a class template
vector_int as a class template
As a class template, we can parameterize vector_int over its
element type
template <typename T>
class vector_int {
...
};
vector_int β†’ vector
Since our container is not limited to int elements anymore, we
rename it vector
template <typename T>
class vector {
...
};
vector_int β†’ vector
We then subs*tute all occurrences of int with T
template <typename T>
class vector {
public:
using iterator = T*;
using const_iterator = T const*;
vector(std::size_t sz): sz(sz), elem(new T[sz]) {...}
T& operator(std::size_t i) { return elem[i]; }
T const& operator(std::size_t i) const { return elem[i]; }
...
private:
std::size_t sz;
T* elem;
};
vector
As a result, we obtained a non-resizable container of con5guously-
allocated elements of type T
vector<double> v(3);
v[0] = 7.1;
v[1] = 2.9;
v[2] = 5.3;
vector preserves regularity
Moreover, vector is as regular as its element type
// T is either a semi-regular,
// regular or totally ordered type
template <typename T>
class vector { ... }
vector preserves regularity
In other words, vector is a regularity-preserving type constructor
// T is either a semi-regular,
// regular or totally ordered type
template <typename T>
class vector { ... }
vector vs. min_element
template <typename I>
I min_element(I first, I last) { ... }
void print_min(vector<double> v) {
vector<double>::iterator first = v.begin();
vector<double>::iterator last = v.end();
vector<double>::iterator m = min_element(first, last);
if (m != last)
std::cout << "the min is " << *m;
}
vector vs. min_element
template <typename I>
I min_element(I first, I last) { ... }
void print_min(vector<double> v) {
auto first = v.begin();
auto last = v.end();
auto m = min_element(first, last);
if (m != last)
std::cout << "the min is " << *m;
}
Func%on objects
The book regular type
class book {
public:
book() {}
book(std::string title,
std::string isbn,
int pub_year): title(title), isbn(isbn), pub_year(pub_year) {}
bool operator<(book const& b) const { return isbn < b.isbn; }
bool operator==(book const& b) const { return isbn == b.isbn; }
// definitions for !=, <, >=, <=
private:
std::string title;
std::string isbn;
int pub_year;
};
Finding the minimum book
Hence, we can find the lexicographic minimum book in a vector as:
std::vector<book> bs = ...
auto m = min_element(bs.begin(), bs.end());
Finding the most ancient book
What if we want to find instead the most ancient book?
class book {
public:
...
bool operator<(book const& b) const { return isbn < b.isbn; }
private:
std::string title;
std::string isbn;
int pub_year;
};
Finding the most ancient book
Unfortunately, there could be only one natural order for a class
class book {
public:
...
bool operator<(book const& b) const { return isbn < b.isbn; }
private:
std::string title;
std::string isbn;
int pub_year;
};
Finding the most ancient book
Moreover, min_element is wri+en so as to use operator <
template <typename I>
I min_element(I first, I last) {
if (first == last) return last;
I min = first; ++first;
while (first != last) {
if (*first < *min) min = first;
++first;
}
return min;
}
Less-than operator
However, forcing the use of operator < seems an arbitrary choice
template <typename I>
I min_element(I first, I last) {
if (first == last) return last;
I min = first; ++first;
while (first != last) {
if (*first < *min) min = first;
++first;
}
return min;
}
Less-than operator
This is evident if we use the func/onal nota/on3
of operator<
template <typename I>
I min_element(I first, I last) {
if (first == last) return last;
I min = first; ++first;
while (first != last) {
if (operator<(*first, *min)) min = first;
++first;
}
return min;
}
3
With the caveat that such a nota/on is not possible when the value type of I is a built-in type
Less-than operator
In fact, operator< is just one out of many ordering criteria
template <typename I>
I min_element(I first, I last) {
if (first == last) return last;
I min = first; ++first;
while (first != last) {
if (operator<(*first, *min)) min = first;
++first;
}
return min;
}
A generalized version of min_element
Therefore, the following looks like a be3er generaliza5on:
template <typename I, typename C>
I min_element(I first, I last, C cmp) {
if (first == last) return last;
I min = first; ++first;
while (first != last) {
if (cmp(*first, *min)) min = first;
++first;
}
return min;
}
On the nature of cmp
Since cmp is invoked, one would say that cmp is a func%on
if (cmp(*first, *min)) min = first;
On the nature of cmp
However, cmp is also passed as an input argument, therefore it also
looks like an object
template <typename I, typename C>
I min_element(I first, I last, C cmp) { ... }
On the nature of cmp
Func%on object
It turns out that cmp is an object that behaves like a func3on
template <typename I, typename C>
I min_element(I first, I last, C cmp) { ... }
Func%on object
We refer to such objects as func%on objects4
template <typename I, typename C>
I min_element(I first, I last, C cmp) { ... }
4
Func'on objects are also called functors. However, we prefer not to use such a term, since outside the C++
community it is used to indicate a very different concept
Func%on object
In order to make an object look like a func3on we need to overload
the call operator ()
converter func. object
class converter {
public:
converter(double er): exchange_rate(er) {}
double operator()(double amount) const {
return amount * exchange_rate;
}
private:
double exchange_rate;
};
converter func. object
Once ini'alized with the exchange rate, we can invoke the func'on
object just like a plain func'on
converter eur_to_usd(1.1);
double euros;
std::cin >> euros;
std::cout << eur_to_usd(euros);
The advantage of func. objects
The advantage of func/on objects is that they can be efficiently
passed to func/ons and consequently invoked
template <typename I, typename C>
I min_element(I first, I last, C cmp) { ... }
Comparing books by pub_year
In light of this, we need a func3on object that will take two books
and verify if the first one is older than the second5
struct by_pub_year {
bool operator()(book const& b1,
book const& b2) const {
return b1.pub_year() < b2.pub_year();
}
};
5
Here, we are assuming the existence of an access func5on named pub_year()
Comparing books by pub_year
With by_pub_year in place, we can finally look for the most
ancient book
std::vector<book> bs = ...
auto m = min_element(bs.begin(),
bs.end(), by_pub_year());
Default comparison
However, we would s-ll like to default to operator< when no
custom func-on object is passed
std::vector<book> bs = ...
auto min_isbn = min_element(bs.begin(), bs.end());
less func&on object
To this extent, let us first write a func4on object to serve as the
default comparator, which we call less6
struct less {
template <typename T> // T is a totally ordered type
bool operator(T const& e1, T const& e2) const {
return e1 < e2;
}
};
6
In the C++ Standard, the type parameteriza4on is on the class, rather than on the operator overload. That is, the
standard default comparator is of type std::less<T>
min_element overload
Then, we provide an overload of min_element which wraps the
more general func7on
template <typename I, typename C>
I min_element(I first, I last, C cmp) { ... }Β Β Β Β Β Β Β Β Β Β Β Β Β 
template <typename I>
I min_element(I first, I last) {
return min_element(first, last, less());
}
Finding the minimum book
Thanks to this, we are free to decide if we want to pass or not a
custom comparator
std::vector<book> bs = ...
auto min_isbn = min_element(bs.begin(), bs.end());
auto min_pub = min_element(bs.begin(), bs.end(), by_pub_year());
Does by_pub_year induce a strict total order on books?
py_pub_year vs. strict total order
As a ma&er of fact, by_pub_year does not induce a strict total
order
struct by_pub_year {
...
};
py_pub_year vs. strict total order
Indeed, the trichotomy law would impose two books with the same
publishing date to be the same
!by_pub_year({"The dubliners", 1914}, {"The metamorphosis ", 1914}) &&
!by_pub_year({"The metamorphosis ", 1914}, {"The dubliners", 1914})
Equivalent rela-on
No#ce that the property of having the same publishing date is an
equivalent rela,on
Equivalent classes
As such, it par--ons the set of books into equivalent classes
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ β”‚ * * β”‚ β”‚
β”‚ * β”‚ * 1851 * β”‚ * β”‚
β”‚ * β”‚ * * β”‚ * β”‚
β”‚ * │─────────────────────┬────────│ * β”‚
β”‚ β”‚ * β”‚ β”‚ β”‚
β”‚ β”‚ * 2005 * β”‚ * β”‚ 1712 β”‚
β”‚ 1987 β”‚ * * β”‚ β”‚ β”‚
β”‚ │──────────┬─────────── 2016 β”‚ * * β”‚
β”‚ * β”‚ β”‚ * β”‚ β”‚ β”‚
β”‚ * β”‚ * * β”‚ * β”‚ * * β”‚ β”‚
β”‚ * β”‚ β”‚ │────────┴──────────
β”‚ β”‚ 1901 β”‚ 1301 β”‚ * * β”‚
β”‚ * β”‚ * * β”‚ β”‚ 1510 β”‚
β”‚ * * β”‚ * β”‚ * β”‚ * * β”‚
β”‚ β”‚ β”‚ β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Strict weak ordering
A strict weak ordering is an ordering rela-on that is strict,
transi/ve and obeys the weak-trichotomy law
Weak-trichotomy law
An ordering rela,on r obeys the weak-trichotomy law if
!r(a, b) && !r(b, a) is the same as eq(a, b),
for some equivalent rela0on eq
Weak vs. total ordering
Therefore, a strict total ordering is a par-cular case of weak total
ordering in which equality is used as the equivalent rela-on
min_element requirements
Finally, we can state the correct requirements for min_element
// I is a forward iterator
// C defines a strict weak ordering on I's value type
template <typename I, typename C>
I min_element(I first, I last, C cmp) { ... }
Generic programming
Generic programming
The Standard Template Library is the most successful example of a
programming paradigm called generic programming7
7
With the Boost library steadily holding the second posi5on
Generic programming
Generic programming is an approach to programming that focuses
on designing algorithms and data structures so that they work in
the most general se0ng without loss of efficiency
Generic programming
That is, generic programming is a way of developing so7ware that
maximizes code reuse without sacrificing performance
Generic programming
Generic programming achieves this through parameteriza)on
Parameteriza)on
We can parameterize a type with another (such as a vector with
its element type)
template <typename T>
class vector {
...
}
Parameteriza)on
We can parameterize an algorithm with an other (such as the
min_element func6on with a comparison func. object)
template <typename I, typename C>
I min_element(I first, I last, C cmp) {...}
Polymorphism
Non-generic func-ons are monomorphic, i.e., they operate on one
data type
int* min_element(int* first, int* last) {...}
Polymorphism
For example, the following non-generic version of min_element is
specific to arguments of type int*
int* min_element(int* first, int* last) {...}
Polymorphism
On the contrary, generic func1ons are polymorphic, i.e., they
operate on any data type so long as their requirements hold
// I is a forward iterator
// C defines a strict weak ordering on I's value type
template <typename I, typename C>
I min_element(I first, I last, C cmp) {...}
Parametric polymorphism
This form of polymorphism is usually called parametric
polymorphism, as opposed to ad-hoc polymorphism, which is
typical of the object-oriented paradigm
Most general algorithms
Generic programming tries to discover polymorphic func6ons by
observing that several monomorphic func6ons all share a similar
structure
Most general algorithms
That is, generic programming tries to define algorithms in terms of
the most general concepts
Avoid par*al solu*ons
The availability of correct generic algorithms allows developers to
avoid wri7ng their own par$ally correct ones
Avoid par*al solu*ons
Thanks to this, developers can avoid using statements such as for
and while that can cause non-robust behavior
Avoid par*al solu*ons
With min_element, we should not need any more to iterate over
a container with a for loop just for the sake of finding the
minimum element
Avoid par*al solu*ons
"Photoshop is roughly 3 million lines of code last 7me I counted, which
means I think we will be able to express the en7re Photoshop in about
30 thousand lines of code"
(S. Parent)
Before using the STL
void PanelBar::RepositionExpandedPanels(Panel* fixed_panel) {
CHECK(fixed_panel);
// First, find the index of the fixed panel.
int fixed_index = GetPanelIndex(expanded_panels_, *fixed_panel);
CHECK_LT(fixed_index, expanded_panels_.size());
// Next, check if the panel has moved to the other side of another panel.
const int center_x = fixed_panel->cur_panel_center();
for (size_t i = 0; i < expanded_panels_.size(); ++i) {
Panel* panel = expanded_panels_[i].get();
if (center_x <= panel->cur_panel_center() ||
i == expanded_panels_.size() - 1) {
if (panel != fixed_panel) {
// If it has, then we reorder the panels.
ref_ptr<Panel> ref = expanded_panels_[fixed_index];
expanded_panels_.erase(expanded_panels_.begin() + fixed_index);
if (i < expanded_panels_.size()) {
expanded_panels_.insert(expanded_panels_.begin() + i, ref);
} else {
expanded_panels_.push_back(ref);
}
}
break;
}
}
A"er using the STL
// Next, check if the panel has moved to the left side of another panel.
auto f = begin(expanded_panels_) + fixed_index;
auto p = lower_bound(begin(expanded_panels_), f, center_x,
[](const ref_ptr<Panel>& e, int x){ return e->cur_panel_center() < x; });
// If it has, then we reorder the panels.
rotate(p, f, f + 1);
Bibliography
Bibliography
β€’ B. Stroustrup, Programming: Principles and Prac8ce
Using C++ (2nd
ed.)
β€’ A. Stepanov, P. McJones, Elements of programming
β€’ A. Stepanov, D. Rose, From Mathema8cs to Generic
Programming
Bibliography
β€’ A. Stepanov, Notes on programming
β€’ A. Stepanov, Efficient Programming with Components Lecture 4
β€’ A. Stepanov, Efficient Programming with Components Lecture 11
β€’ S. Parent, A Possible Future of SoCware Development
β€’ S. Parent, Programming ConversaEons Lecture 5
β€’ S. T. Lavavej, Standard Template Library (STL), 1 of n
Bibliography
β€’ B. Stroustrup, C++ in 2005
β€’ B. Stroustrup, What is "generic programming"?
β€’ ISO C++, What's the big deal with generic programming?

More Related Content

What's hot

exception handling in java.ppt
exception handling in java.pptexception handling in java.ppt
exception handling in java.pptVarshini62
Β 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP FunctionsAhmed Swilam
Β 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
Β 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaAtul Sehdev
Β 
List in java
List in javaList in java
List in javanitin kumar
Β 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsNilesh Dalvi
Β 
Constants in java
Constants in javaConstants in java
Constants in javaManojkumar C
Β 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptWojciech Dzikowski
Β 
Packages in java
Packages in javaPackages in java
Packages in javajamunaashok
Β 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in JavaNaz Abdalla
Β 
Data types in php
Data types in phpData types in php
Data types in phpilakkiya
Β 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++Tech_MX
Β 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection frameworkankitgarg_er
Β 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and StreamsVenkata Naga Ravi
Β 
Java interfaces
Java interfacesJava interfaces
Java interfacesRaja Sekhar
Β 
Files in php
Files in phpFiles in php
Files in phpsana mateen
Β 

What's hot (20)

Java Arrays
Java ArraysJava Arrays
Java Arrays
Β 
exception handling in java.ppt
exception handling in java.pptexception handling in java.ppt
exception handling in java.ppt
Β 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
Β 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Β 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in java
Β 
List in java
List in javaList in java
List in java
Β 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Β 
Constants in java
Constants in javaConstants in java
Constants in java
Β 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
Β 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Β 
Packages in java
Packages in javaPackages in java
Packages in java
Β 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Β 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
Β 
Exception handling
Exception handlingException handling
Exception handling
Β 
Data types in php
Data types in phpData types in php
Data types in php
Β 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
Β 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
Β 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
Β 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Β 
Files in php
Files in phpFiles in php
Files in php
Β 

Viewers also liked

Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template LibraryKumar Gaurav
Β 
How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)Sangharsh agarwal
Β 
C++ Template
C++ TemplateC++ Template
C++ TemplateSaket Pathak
Β 
Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-libraryHariz Mustafa
Β 
Templates presentation
Templates presentationTemplates presentation
Templates presentationmalaybpramanik
Β 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
Β 
はまる!JPAοΌˆεˆε­¦θ€…ε‘γ‘γƒ©γ‚€γƒˆη‰ˆοΌ‰
はまる!JPAοΌˆεˆε­¦θ€…ε‘γ‘γƒ©γ‚€γƒˆη‰ˆοΌ‰γ―γΎγ‚‹οΌJPAοΌˆεˆε­¦θ€…ε‘γ‘γƒ©γ‚€γƒˆη‰ˆοΌ‰
はまる!JPAοΌˆεˆε­¦θ€…ε‘γ‘γƒ©γ‚€γƒˆη‰ˆοΌ‰Masatoshi Tada
Β 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template LibraryDuda Dornelles
Β 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++Ilio Catallo
Β 
Resource wrappers in C++
Resource wrappers in C++Resource wrappers in C++
Resource wrappers in C++Ilio Catallo
Β 
C++ STL 概觀
C++ STL 概觀C++ STL 概觀
C++ STL 概觀PingLun Liao
Β 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++ppd1961
Β 
Operator overloading in C++
Operator overloading in C++Operator overloading in C++
Operator overloading in C++Ilio Catallo
Β 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++Ilio Catallo
Β 
Templates in c++
Templates in c++Templates in c++
Templates in c++Mayank Bhatt
Β 
Spring MVC - Web Forms
Spring MVC  - Web FormsSpring MVC  - Web Forms
Spring MVC - Web FormsIlio Catallo
Β 
Testing Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsTesting Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsSam Brannen
Β 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + SpringBryan Hsueh
Β 

Viewers also liked (20)

Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
Β 
How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)
Β 
C++ Template
C++ TemplateC++ Template
C++ Template
Β 
Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-library
Β 
Templates presentation
Templates presentationTemplates presentation
Templates presentation
Β 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Β 
はまる!JPAοΌˆεˆε­¦θ€…ε‘γ‘γƒ©γ‚€γƒˆη‰ˆοΌ‰
はまる!JPAοΌˆεˆε­¦θ€…ε‘γ‘γƒ©γ‚€γƒˆη‰ˆοΌ‰γ―γΎγ‚‹οΌJPAοΌˆεˆε­¦θ€…ε‘γ‘γƒ©γ‚€γƒˆη‰ˆοΌ‰
はまる!JPAοΌˆεˆε­¦θ€…ε‘γ‘γƒ©γ‚€γƒˆη‰ˆοΌ‰
Β 
C++ Templates 2
C++ Templates 2C++ Templates 2
C++ Templates 2
Β 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
Β 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
Β 
Resource wrappers in C++
Resource wrappers in C++Resource wrappers in C++
Resource wrappers in C++
Β 
C++ STL 概觀
C++ STL 概觀C++ STL 概觀
C++ STL 概觀
Β 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
Β 
Operator overloading in C++
Operator overloading in C++Operator overloading in C++
Operator overloading in C++
Β 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++
Β 
Templates in c++
Templates in c++Templates in c++
Templates in c++
Β 
Spring MVC - Web Forms
Spring MVC  - Web FormsSpring MVC  - Web Forms
Spring MVC - Web Forms
Β 
Testing Spring MVC and REST Web Applications
Testing Spring MVC and REST Web ApplicationsTesting Spring MVC and REST Web Applications
Testing Spring MVC and REST Web Applications
Β 
Templates
TemplatesTemplates
Templates
Β 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
Β 

Similar to C++ Standard Template Library

ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxpriestmanmable
Β 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming LanguageDipankar Achinta
Β 
Lecture1_cis4930.pdf
Lecture1_cis4930.pdfLecture1_cis4930.pdf
Lecture1_cis4930.pdfzertash1
Β 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0Yaser Zhian
Β 
Java New Programming Features
Java New Programming FeaturesJava New Programming Features
Java New Programming Featurestarun308
Β 
Time and Space Complexity Analysis.pptx
Time and Space Complexity Analysis.pptxTime and Space Complexity Analysis.pptx
Time and Space Complexity Analysis.pptxdudelover
Β 
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNew c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNico Ludwig
Β 
Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Pythonshailaja30
Β 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seoJinTaek Seo
Β 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxAbhishek Tirkey
Β 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxGauravPandey43518
Β 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMSfawzmasood
Β 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptxsangeeta borde
Β 
Loops_in_Rv1.2b
Loops_in_Rv1.2bLoops_in_Rv1.2b
Loops_in_Rv1.2bCarlo Fanara
Β 
DA lecture 3.pptx
DA lecture 3.pptxDA lecture 3.pptx
DA lecture 3.pptxSayanSen36
Β 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5ecomputernotes
Β 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
Β 
Theory of algorithms final
Theory of algorithms final Theory of algorithms final
Theory of algorithms final Dgech
Β 

Similar to C++ Standard Template Library (20)

ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
Β 
Cat's anatomy
Cat's anatomyCat's anatomy
Cat's anatomy
Β 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
Β 
Lecture1_cis4930.pdf
Lecture1_cis4930.pdfLecture1_cis4930.pdf
Lecture1_cis4930.pdf
Β 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0
Β 
Java New Programming Features
Java New Programming FeaturesJava New Programming Features
Java New Programming Features
Β 
Time and Space Complexity Analysis.pptx
Time and Space Complexity Analysis.pptxTime and Space Complexity Analysis.pptx
Time and Space Complexity Analysis.pptx
Β 
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNew c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iii
Β 
Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Python
Β 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
Β 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Β 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
Β 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
Β 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
Β 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
Β 
Loops_in_Rv1.2b
Loops_in_Rv1.2bLoops_in_Rv1.2b
Loops_in_Rv1.2b
Β 
DA lecture 3.pptx
DA lecture 3.pptxDA lecture 3.pptx
DA lecture 3.pptx
Β 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5
Β 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
Β 
Theory of algorithms final
Theory of algorithms final Theory of algorithms final
Theory of algorithms final
Β 

More from Ilio Catallo

Memory management in C++
Memory management in C++Memory management in C++
Memory management in C++Ilio Catallo
Β 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++Ilio Catallo
Β 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++Ilio Catallo
Β 
Spring MVC - Wiring the different layers
Spring MVC -  Wiring the different layersSpring MVC -  Wiring the different layers
Spring MVC - Wiring the different layersIlio Catallo
Β 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platformsIlio Catallo
Β 
Spring MVC - The Basics
Spring MVC -  The BasicsSpring MVC -  The Basics
Spring MVC - The BasicsIlio Catallo
Β 
Web application architecture
Web application architectureWeb application architecture
Web application architectureIlio Catallo
Β 
Introduction To Spring
Introduction To SpringIntroduction To Spring
Introduction To SpringIlio Catallo
Β 
Gestione della memoria in C++
Gestione della memoria in C++Gestione della memoria in C++
Gestione della memoria in C++Ilio Catallo
Β 
Array in C++
Array in C++Array in C++
Array in C++Ilio Catallo
Β 
Puntatori e Riferimenti
Puntatori e RiferimentiPuntatori e Riferimenti
Puntatori e RiferimentiIlio Catallo
Β 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence APIIlio Catallo
Β 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag LibraryIlio Catallo
Β 
Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3Ilio Catallo
Β 
Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3Ilio Catallo
Β 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3Ilio Catallo
Β 
Community Detection
Community DetectionCommunity Detection
Community DetectionIlio Catallo
Β 
WWW12 - The CUbRIK Project
WWW12 - The CUbRIK ProjectWWW12 - The CUbRIK Project
WWW12 - The CUbRIK ProjectIlio Catallo
Β 

More from Ilio Catallo (18)

Memory management in C++
Memory management in C++Memory management in C++
Memory management in C++
Β 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++
Β 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++
Β 
Spring MVC - Wiring the different layers
Spring MVC -  Wiring the different layersSpring MVC -  Wiring the different layers
Spring MVC - Wiring the different layers
Β 
Java and Java platforms
Java and Java platformsJava and Java platforms
Java and Java platforms
Β 
Spring MVC - The Basics
Spring MVC -  The BasicsSpring MVC -  The Basics
Spring MVC - The Basics
Β 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
Β 
Introduction To Spring
Introduction To SpringIntroduction To Spring
Introduction To Spring
Β 
Gestione della memoria in C++
Gestione della memoria in C++Gestione della memoria in C++
Gestione della memoria in C++
Β 
Array in C++
Array in C++Array in C++
Array in C++
Β 
Puntatori e Riferimenti
Puntatori e RiferimentiPuntatori e Riferimenti
Puntatori e Riferimenti
Β 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
Β 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag Library
Β 
Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3Internationalization in Jakarta Struts 1.3
Internationalization in Jakarta Struts 1.3
Β 
Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3Validation in Jakarta Struts 1.3
Validation in Jakarta Struts 1.3
Β 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3
Β 
Community Detection
Community DetectionCommunity Detection
Community Detection
Β 
WWW12 - The CUbRIK Project
WWW12 - The CUbRIK ProjectWWW12 - The CUbRIK Project
WWW12 - The CUbRIK Project
Β 

Recently uploaded

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
Β 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
Β 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
Β 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
Β 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
Β 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
Β 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
Β 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
Β 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
Β 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
Β 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
Β 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
Β 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
Β 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
Β 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
Β 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
Β 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
Β 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
Β 

Recently uploaded (20)

costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
Β 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
Β 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
Β 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Β 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Β 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
Β 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Β 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Β 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
Β 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
Β 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
Β 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
Β 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Β 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
Β 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Β 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
Β 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
Β 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
Β 
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort ServiceHot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Β 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
Β 

C++ Standard Template Library

  • 1. Standard Template Library Ilio Catallo - info@iliocatallo.it
  • 2. Outline β€’ Introduc*on β€’ Ideals and concepts β€’ Generic programming β€’ Bibliography
  • 4. The Standard Template Library The C++ Standard Library includes a set of algorithms and data structures that were originally part of a third-party library, called the Standard Template Library (STL)
  • 5. The Standard Template Library The Standard Template Library was invented by Alexander Stepanov in 1994 circa, and later included in the C++ Standard Library
  • 6. The Standard Template Library The STL is the outcome of two decades of Stepanov's effort in delinea8ng the fundamental principles of programming
  • 7. The Standard Template Library Before turning to C++, Stepanov unsuccessfully tried implemen9ng the STL using languages such as Scheme and Ada
  • 8. An approach to computa-on "The STL is unlike any other library you have seen before." (S. T. Lavavej)
  • 9. An approach to computa-on "People look at STL and think it's a nice container and algorithm library. It is not, it is a different way of thinking about code." (S. Parent)
  • 10. What makes the STL so special?
  • 11. Storing and manipula/ng objects Consider the problem of storing objects in containers and wri6ng algorithms to manipulate such objects
  • 12. Storing and manipula/ng objects We want to be able to store objects of a variety of types in a variety of containers and to apply a variety of algorithms
  • 13. Storing and manipula/ng objects Furthermore, we want the use of these objects, containers, and algorithms to be: β€’ Sta%cally type safe β€’ As fast possible β€’ As compact as possible β€’ Not verbose and readable
  • 14. Storing and manipula/ng objects "Achieving all of this simultaneously isn't easy. In fact, I spent about 10 years unsuccessfully looking for a solu>on to this puzzle." (B. Stroustrup)
  • 15. List inser)on In order to appreciate this, let us consider the problem of inser5ng an arbitrary long sequence of progressive numbers into a list
  • 16. List inser)on We will see how to solve this problem using STL and Glib1 1 Glib is a general-purpose C library associated with the GNOME desktop environment. For more informaBon about GLib, see hEps://developer.gnome.org/glib/stable/
  • 17. STL: inser+on std::list<int> l; for (int i = 0; i < 10; i++) l.push_back(i);
  • 18. Glib: inser+on GList* list = NULL; int* data_ptr; for (int i = 0; i < 10; i++) { data_ptr = g_new(int, 1); *data_ptr = i; list = g_list_append(list, (void*) data_ptr); }
  • 19. The NΒ·M problem Before the STL, all the available general computa8on libraries suffered from the NΒ·M problem
  • 20. The NΒ·M problem If you have N containers and M algorithms, you need NΒ·M different implementa;ons in order to provide each algorithm for each possible container
  • 21. Glib: finding in a doubly-linked list GList* list = ...; GList* tmp; int* data_ptr; data_ptr = g_new(int, 1); *data_ptr = 7; tmp = g_list_find(list, (void*) data_ptr);
  • 22. Glib: finding in a singly-linked list GSList* list = ...; GSList* tmp; int* data_ptr; data_ptr = g_new(int, 1); *data_ptr = 7; tmp = g_slist_find(list, (void*) data_ptr);
  • 23. The STL solu+on The STL solu+on is based on parameterizing containers with their element types and on completely separa-ng the algorithms from the containers
  • 24. STL: finding in a doubly-linked list std::list<int> l = {1, 10, 8, 7}; auto p = std::find(l.begin(), l.end(), 7);
  • 25. STL: finding in a singly-linked list std::forward_list<int> l = {1, 10, 8, 7}; auto p = std::find(l.begin(), l.end(), 7);
  • 26. The STL is extensible Since containers and algorithms are independent, introducing a new container does not require reimplemen6ng all the available algorithms
  • 27. The STL is extensible All available algorithms will simply work with the new container
  • 29. The STL components The STL is composed of three main components, namely, algorithms, iterators and containers β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ use β”‚ β”‚ expose β”‚ β”‚ β”‚ Algorithms │────────▢│ Iterators β”‚ ──────────│ Containers β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • 30. The STL components Moreover, func%on objects are used to customize both algorithms and containers β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ use β”‚ β”‚ expose β”‚ β”‚ β”‚ Algorithms │─────────▢│ Iterators β”‚ ─────────│ Containers β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β–² β–² β”‚ β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ customize β”‚ β”‚ customize β”‚ └────────────────────│ Function objects β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • 32. The swap func)on We extensively discussed the proper.es of the swap func.on
  • 33. swap alterna(ves At first, we wrote several alterna*ves of the swap func0on, each of which tailored for a specific built-in type void swap(int& x, int& y) { int tmp = x; x = y; y = tmp; }
  • 34. swap alterna(ves At first, we wrote several alterna*ves of the swap func0on, each of which tailored for a specific built-in type void swap(double& x, double& y) { double tmp = x; x = y; y = tmp; }
  • 35. swap alterna(ves At first, we wrote several alterna*ves of the swap func0on, each of which tailored for a specific built-in type void swap(char& x, char& y) { char tmp = x; x = y; y = tmp; }
  • 36. swap for built-in types Later, we no+ced that we can devise a uniform implementa.on of swap for any built-in type T // T is a built-in type void swap(T& x, T& y) { T tmp = x; x = y; y = tmp; }
  • 37. swap for semi-regular types Ul#mately, we observed that the very same implementa#on is s#ll valid for any copy-construc+ble and assignable type // T is copy-constructible and assignable void swap(T& x, T& y) { T tmp = x; x = y; y = tmp; }
  • 38. swap for semi-regular types That is, the same implementa.on is valid for any semi-regular type // T is semi-regular void swap(T& x, T& y) { T tmp = x; x = y; y = tmp; }
  • 39. Language limita,ons Unsurprisingly, the following code does not compile // T is semi-regular void swap(T& x, T& y) { T tmp = x; x = y; y = tmp; }
  • 40. Language limita,ons Unsurprisingly, the following code does not compile // void swap(T& x, T& y) { // ^ // error: 'T' was not declared in this scope
  • 41. Language limita,ons This is because the compiler requires func4on parameters to be exis%ng types // T is semi-regular void swap(T& x, T& y) { T tmp = x; x = y; y = tmp; }
  • 42. Language limita,ons Apparently, the language is limi&ng us in harnessing the underlying regularity we were able to no5ce // T is semi-regular void swap(T& x, T& y) { T tmp = x; x = y; y = tmp; }
  • 43. Func%on templates To solve this, we will turn swap into a func%on template
  • 44. Func%on templates A func'on template defines a family of func,ons, rather than a single func'on
  • 45. swap as a func(on template This allows us to define at once all the alterna1ve versions of swap function template: swap(T&, T&) β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β€’ swap(double&, double&) β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ swap(int&, int&) β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ swap(char&, char&) β”‚ β”‚ β”‚ β”‚ β€’ swap(float&, float&) β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β€’ swap(vector_int&, vector_int&) β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • 46. swap as a func(on template The defini)on of swap as a func)on template is as follows: template <typename T> // T is semi-regular void swap(T& x, T& y) { T tmp = x; x = y; y = tmp; }
  • 47. Template instan,a,on The func. template generates as many actual func1ons as needed T = double β†’ swap(double&, double&)
  • 48. Template instan,a,on The func. template generates as many actual func1ons as needed T = int β†’ swap(int&, int&)
  • 49. Template instan,a,on The func. template generates as many actual func1ons as needed T = char β†’ swap(char&, char&)
  • 50. Template instan,a,on Func%on templates are instan%ated at compile-)me template <typename T> void swap(T& x, T& y) { ... } int main() { float f1 = 3.4, f2 = 7.3; char c1 = 'a', c2 = 'b'; swap(f1, f2); swap(c1, c2); }
  • 51. Template instan,a,on Func%on templates are instan%ated at compile-)me void swap(float& x, float& y) { ... } void swap(char& x, char& y) { ... } int main() { float f1 = 3.4, f2 = 7.3; char c1 = 'a', c2 = 'b'; swap(f1, f2); swap(c1, c2); }
  • 52. std::swap In fact, we derived the defini1on of std::swap as of C++03 template <typename T> // T is semi-regular void swap(T& x, T& y) { T tmp = x; x = y; y = tmp; }
  • 54. The min_element algorithm In a previous lecture, we devised an algorithm for finding the minimum element of an integer array
  • 55. The min_element algorithm int* min_element(int* first, int* last) { if (first == last) return last; int* min = first; ++first; while (first != last) { if (*first < *min) min = first; ++first; } return min; }
  • 56. The min_element algorithm It is immediate to see that the procedure does not depend on the elements being integers int* min_element(int* first, int* last) { ... }
  • 57. The min_element algorithm It is immediate to see that the procedure does not depend on the elements being integers double* min_element(double* first, double* last) { ... }
  • 58. The min_element algorithm It is immediate to see that the procedure does not depend on the elements being integers char* min_element(char* first, char* last) { ... }
  • 59. The min_element algorithm Hence, we can write min_element as a func%on template template <typename I> I min_element(I first, I last) { ... }
  • 60. min_element as a func(on template template <typename I> I min_element(I first, I last) { if (first == last) return last; I min = first; ++first; while (first != last) { if (*first < *min) min = first; ++first; } return min; }
  • 61. Element type independence We can now invoke min_element regardless of the element type template <typename I> I min_element(I first, I last) { ... }
  • 62. Using min_element template <typename I> I min_element(I first, I last) { ... } int main() { double ds[] = {7.1, 2.3, 5.6, 9.0}; char cs[] = {'a', 'b', 'c'}; double* d = min_element(ds, ds + 4); char* c = min_element(cs, cs + 3); }
  • 63. Using min_element I is derived to be double* when passing an array of m elements of type double template <typename I> I min_element(I first, I last) { ... }
  • 64. Using min_element I is derived to be char* when passing an array of m elements of type char template <typename I> I min_element(I first, I last) { ... }
  • 65. Can we use min_element on linked lists?
  • 66. Finding the minimum The algorithm for finding the minimum is independent of the way we store elements in memory β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬ ─ ┐ xs: β”‚ 1 β”‚ 7 β”‚13 β”‚ 5 β”‚ └───┴───┴───┴───┴ ─ β”˜ β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” xs: β”‚ 1 β”œβ”€β”€β”€ 7 β”œβ”€β”€β”€13 β”œβ”€β”€β”€ 5 │──▢ * β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜
  • 67. Finding the minimum Because of this, we should be able to apply min_element on linked lists as well β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬ ─ ┐ xs: β”‚ 1 β”‚ 7 β”‚13 β”‚ 5 β”‚ └───┴───┴───┴───┴ ─ β”˜ β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” β”Œβ”€β”€β”€β” xs: β”‚ 1 β”œβ”€β”€β”€ 7 β”œβ”€β”€β”€13 β”œβ”€β”€β”€ 5 │──▢ * β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜ β””β”€β”€β”€β”˜
  • 68. Requirements on I For min_element to work, we need some proper/es to hold for I template <typename I> I min_element(I first, I last) { if (first == last) return last; I min = first; ++first; while (first != last) { if (*first < *min) min = first; ++first; } return min; }
  • 69. Requirements on I Namely, we require I to be: β€’ Equality & inequality comparable β€’ Copy construc6ble & assignable β€’ Incrementable
  • 70. Passing a pointer For arrays, I is derived to be a pointer template <typename I> I min_element(I first, I last) { ... }
  • 71. Passing a pointer Since pointers sa-sfy the requirements we iden-fied, the algorithm works template <typename I> I min_element(I first, I last) { ... }
  • 72. Linked lists However, intrusive linked lists are usually implemented as struct node { int value; node* next; };
  • 73. Linked lists Therefore, we need to subs0tute pointers with a user-defined type that s0ll meets the requirements for I template <typename I> I min_element(I first, I last) { ... }
  • 74. Iterators We refer to such user-defined types as iterators class list_iterator { ... };
  • 75. Linked list iterator Namely, we will write a class named list_iterator to be used in conjunc5on with the node class class list_iterator { ... };
  • 76. list_iterator representa)on class list_iterator { public: ... private: ??? };
  • 77. list_iterator representa)on class list_iterator { public: ... private: node* curr; };
  • 78. list_iterator constructor class list_iterator { public: list_iterator(???): ??? { ??? } private: node* curr; };
  • 79. list_iterator constructor class list_iterator { public: list_iterator(node* curr): curr(curr) {} private: node* curr; };
  • 80. list_iterator default constructor class list_iterator { public: list_iterator(node* curr): curr(curr) {} list_iterator(): curr(nullptr) {} private: node* curr; };
  • 81. Dereference overload class list_iterator { public: list_iterator(node* curr): curr(curr) {} list_iterator(): curr(nullptr) {} ??? operator*() ??? { ??? } private: node* curr; };
  • 82. Dereference overload class list_iterator { public: list_iterator(node* curr): curr(curr) {} list_iterator(): curr(nullptr) {} int& operator*() const { return curr->value; } private: node* curr; };
  • 83. Dereference constness Note that operator* is always const, even for non-const iterators int& operator*() const { return curr->value; }
  • 84. Dereference constness Constness only means that the iterator cannot be later modified so as to point to a different posi5on in the data structure list_iterator const it1 = ...; it1 = it2; // it1 cannot be re-assigned so as to point to a different location
  • 85. Dereference constness Nevertheless, it is perfectly valid to modify the data pointed to by a constant iterator list_iterator const it1 = ...; *it1 = 10;
  • 86. Dereference constness Recall that we are trying to mimic pointers, and this is perfectly aligned with the way pointers behave: int a = 10, b = 7; int* const p = &a; p = &b; // error: p is a constant pointer *p = 5; // legit: a is now 5
  • 87. Prefix increment overload class list_iterator { public: list_iterator(node* curr): curr(curr) {} list_iterator(): curr(nullptr) {} int& operator*() const { return curr->value; } ??? operator++() { ??? } private: node* curr; };
  • 88. Prefix increment overload class list_iterator { public: list_iterator(node* curr): curr(curr) {} list_iterator(): curr(nullptr) {} int& operator*() const { return curr->value; } list_iterator& operator++() { curr = curr->next; return *this; } private: node* curr; };
  • 89. Equality overload class list_iterator { public: list_iterator(node* curr): curr(curr) {} list_iterator(): curr(nullptr) {} int& operator*() const { return curr->value; } list_iterator& operator++() { curr = curr->next; return *this; } bool operator==(list_iterator& y) const { ??? } private: node* curr; };
  • 90. Equality overload class list_iterator { public: list_iterator(node* curr): curr(curr) {} list_iterator(): curr(nullptr) {} int& operator*() const { return curr->value; } list_iterator& operator++() { curr = curr->next; return *this; } bool operator==(list_iterator& y) const { return curr == y.curr; } private: node* curr; };
  • 91. Inequality overload class list_iterator { public: list_iterator(node* curr): curr(curr) {} list_iterator(): curr(nullptr) {} int& operator*() const { return curr->value; } list_iterator& operator++() { curr = curr->next; return *this; } bool operator==(list_iterator& y) const { return curr == y.curr; } bool operator!=(list_iterator& y) const { return !(*this == y); } private: node* curr; };
  • 92. list_iterator list_iterator supports all opera+ons required by min_element template <typename I> I min_element(I first, I last) { ... }
  • 93. min_element void print_min(node* head) { list_iterator first(head); list_iterator last; list_iterator m = min_element(first, last); if (m != last) std::cout << "the min is " << *m; }
  • 94. Algorithms vs. containers Note that min_element is completely unaware of the existence of any container template <typename I> I min_element(I first, I last) { ... }
  • 95. Algorithms vs. containers As a ma&er of fact, min_element works as long as we provide a type that meets the requirements for I template <typename I> I min_element(I first, I last) { ... }
  • 96. Algorithms vs. containers "The reason that data structures and algorithms can work together seamlessly is... that they do not know anything about each other." (A. Stepanov)
  • 97. Iterators delimit sequences An iterator allows abstrac/ng an arbitrary container as a sequence of elements β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬ ─ ┐ β”‚ 7 β”‚12 β”‚ 3 β”‚ └───┴───┴───┴ β”€β–²β”˜ β”‚ β”‚ β”‚ past-the-end element
  • 98. Iterators delimit sequences This is true regardless of the fact that elements may in fact not be con4guously allocated in memory (as with linked lists) 3rd past-the-end 1st 2nd elem. elem. elem. elem. ──────▢ ───────▢ ───────▢ ───────▢ β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β” ... β”‚ β”‚ β”‚///β”‚///β”‚ β”‚ β”‚///β”‚///β”‚ β”‚ β”‚ β”‚ β”‚///β”‚///β”‚ β”‚ β”‚///β”‚///β”‚ ... β””β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”˜ ──▢ 1 byte
  • 99. list_iterator vs. pointers Note that list_iterator does not support all pointer opera*ons class list_iterator { ... };
  • 100. list_iterator vs. pointers For instance, we cannot decrement a list_iterator list_iterator it; --it; // compile-time error;
  • 101. Forward iterators We refer to iterators such as list_iterator as forward iterators
  • 102. Random access iterators A pointer – on the other hand – models a random access iterator, which is the most feature-rich iterator possible
  • 103. Iterator hierarchy β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Iterator β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β–² β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Input Iterator β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β–² β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Forward Iterator β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β–² β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Bidirectional Iterator β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β–² β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Random Access Iterator β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • 104. Requirements on I Therefore, we can now refine the requirements on I template <typename I> I min_element(I first, I last) { ... }
  • 105. Requirements on I Namely, we require I to be a forward iterator template <typename I> I min_element(I first, I last) { ... }
  • 106. Requirements on I Namely, we require I to be a forward iterator template <typename I> // I is a forward iterator I min_element(I first, I last) { ... }
  • 107. Requirements on I Moreover, the type resul/ng from dereferencing the forward iterator (i.e., its value type) should model a totally ordered type // I is a forward iterator // I's value type is a totally ordered type template <typename I> I min_element(I first, I last) { ... }
  • 108. Top-down vs. bo-om-up No#ce that we could not iden#fy the requirements without looking at the implementa)on // I is a forward iterator // I's value type is a totally ordered type template <typename I> I min_element(I first, I last) { ... }
  • 109. Top-down vs. bo-om-up This is to say that – some-mes – we cannot determine the interface in a top-down fashion // I is a forward iterator // I's value type is a totally ordered type template <typename I> I min_element(I first, I last) { ... }
  • 110. Top-down vs. bo-om-up Some%mes, we need to look at the implementa%on to determine the interface // I is a forward iterator // I's value type is a totally ordered type template <typename I> I min_element(I first, I last) { ... }
  • 112. vector_int During previous classes, we were able to incrementally write a simplified version of std::vector called vector_int class vector_int { ... };
  • 113. vector_int class vector_int { public: vector_int(): sz(0), elem(nullptr) {} vector_int(std::size_t sz): sz(sz), elem(new int[sz]) {...} vector_int(vector_int const& v): sz(v.sz), elem(new int[v.sz]) {...} ~vector_int() {...} std::size_t size() const {...} int operator[](std::size_t i) const {...} int& operator[](std::size_t i) {...} vector_int& operator=(vector_int const& v) {...} bool operator<(vector_int const& v) const {...} // definitions for !=, <, >=, <= private: std::size_t sz; int* elem; };
  • 114. vector_int vs. algorithms Unfortunately, vector_int cannot be used with any of the algorithms we previously wrote (e.g., copy and min_element)
  • 115. Algorithms expect iterators As we just saw, algorithms that operate on a sequence expects a pair of iterators, rather than the container per se // I is a forward iterator // I's value type is a totally ordered type template <typename I> I min_element(I first, I last) { ... }
  • 116. vector_int vs. algorithms To solve this, vector_int should be able to expose its own iterators
  • 117. begin() and end() Namely, vector_int should provide two member func8ons named begin() and end()2 2 And possible constant variants cbegin() and cend()
  • 118. begin() and end() begin() and end() should return an iterator to the first and to the past-the-end element, respec2vely β”Œβ”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”€β”¬ ─ ┐ β”‚ 7 β”‚12 β”‚ 3 β”‚ └───┴───┴───┴ β”€β–²β”˜ β”‚ β”‚ β”‚ past-the-end element
  • 119. begin() and end() Let us add begin() and end() to vector_int class vector_int { public: ... ??? begin() { ??? } ??? end() { ??? } private: std::size_t sz; int* elem; };
  • 120. begin() and end() Let us add begin() and end() to vector_int class vector_int { public: ... int* begin() { return elem; } int* end() { return elem + sz; } private: std::size_t sz; int* elem; };
  • 121. Const begin() and end() class vector_int { public: ... int* begin() { return elem; } int* end() { return elem + sz; } int const* begin() const {Β return elem; } int const* end() const { return elem + sz; } private: std::size_t sz; int* elem; };
  • 122. vector_int and min_element template <typename I> I min_element(I first, I last) { ... } void print_min(vector_int v) { int* first = v.begin(); int* last = v.end(); int* m = min_element(first, last); if (m != last) std::cout << "the min is " << *m; }
  • 123. vector_int and min_element Although the code works, we s1ll have a issue void print_min(vector_int v) { int* first = v.begin(); int* last = v.end(); int* m = min_element(first, last); if (m != last) std::cout << "the min is " << *m; }
  • 124. vector_int and min_element More precisely, we are revealing too much about the type of the iterator int* first = v.begin(); int* last = v.end();
  • 125. vector_int and min_element Users of vector_int should not be concerned with the fact that iterators are either pointers or user-defined types int* first = v.begin(); int* last = v.end();
  • 126. Member type aliases Thus, we will hide the actual type of the iterator through the use of member type aliases (or simply member types)
  • 127. Member type aliases Member types are type aliases that are defined within the scope of a class
  • 128. Type aliases int main() { using integer = int; integer a = 5; // the same as: int a = 5; }
  • 129. Member type aliases class X { public: using integer = int; }; int main() { // the same as: int a = 5; X::integer a = 5; }
  • 130. Iterator member types Type aliases for iterators and const iterators are required to be called, resp., iterator and const_iterator class vector_int { public using iterator = ??? using const_iterator = ??? ... };
  • 131. Iterator member types Type aliases for iterators and const iterators are required to be called, resp., iterator and const_iterator class vector_int { public using iterator = int*; using const_iterator = int const*; ... };
  • 132. Iterator member types We consequently change the return type of begin() and end() class vector_int { public using iterator = int*; using const_iterator = int const*; ... };
  • 133. Iterator member types class vector_int { public: using iterator = int*; using const_iterator = int const*; ... iterator begin() { return elem; } iterator end() { return elem + sz; } const_iterator begin() const {Β return elem; } const_iterator end() const { return elem + sz; } private: std::size_t sz; int* elem; };
  • 134. Random access iterator No#ce that vector_int::iterator is a random access iterator vector_int::iterator first = v.begin(); first = first + 2; // random access
  • 135. std::vector's iterator type Similarly, given a value of type std::vector<T>, the related iterator type is std::vector<T>::iterator std::vector<int> v = {7, 10, 5, 8}; std::vector<int>::iterator first = v.begin(); std::vector<int>::iterator last = v.end();
  • 136. vector_double It is immediate to see that the if we had to write vector_double, its implementa3on would not differ from that of vector_int class vector_double { public: ... private: std::size_t sz; double* elem; };
  • 137. Class template As with algorithms, we can express such a similarity by turning vector_int in a class template
  • 138. vector_int as a class template As a class template, we can parameterize vector_int over its element type template <typename T> class vector_int { ... };
  • 139. vector_int β†’ vector Since our container is not limited to int elements anymore, we rename it vector template <typename T> class vector { ... };
  • 140. vector_int β†’ vector We then subs*tute all occurrences of int with T template <typename T> class vector { public: using iterator = T*; using const_iterator = T const*; vector(std::size_t sz): sz(sz), elem(new T[sz]) {...} T& operator(std::size_t i) { return elem[i]; } T const& operator(std::size_t i) const { return elem[i]; } ... private: std::size_t sz; T* elem; };
  • 141. vector As a result, we obtained a non-resizable container of con5guously- allocated elements of type T vector<double> v(3); v[0] = 7.1; v[1] = 2.9; v[2] = 5.3;
  • 142. vector preserves regularity Moreover, vector is as regular as its element type // T is either a semi-regular, // regular or totally ordered type template <typename T> class vector { ... }
  • 143. vector preserves regularity In other words, vector is a regularity-preserving type constructor // T is either a semi-regular, // regular or totally ordered type template <typename T> class vector { ... }
  • 144. vector vs. min_element template <typename I> I min_element(I first, I last) { ... } void print_min(vector<double> v) { vector<double>::iterator first = v.begin(); vector<double>::iterator last = v.end(); vector<double>::iterator m = min_element(first, last); if (m != last) std::cout << "the min is " << *m; }
  • 145. vector vs. min_element template <typename I> I min_element(I first, I last) { ... } void print_min(vector<double> v) { auto first = v.begin(); auto last = v.end(); auto m = min_element(first, last); if (m != last) std::cout << "the min is " << *m; }
  • 147. The book regular type class book { public: book() {} book(std::string title, std::string isbn, int pub_year): title(title), isbn(isbn), pub_year(pub_year) {} bool operator<(book const& b) const { return isbn < b.isbn; } bool operator==(book const& b) const { return isbn == b.isbn; } // definitions for !=, <, >=, <= private: std::string title; std::string isbn; int pub_year; };
  • 148. Finding the minimum book Hence, we can find the lexicographic minimum book in a vector as: std::vector<book> bs = ... auto m = min_element(bs.begin(), bs.end());
  • 149. Finding the most ancient book What if we want to find instead the most ancient book? class book { public: ... bool operator<(book const& b) const { return isbn < b.isbn; } private: std::string title; std::string isbn; int pub_year; };
  • 150. Finding the most ancient book Unfortunately, there could be only one natural order for a class class book { public: ... bool operator<(book const& b) const { return isbn < b.isbn; } private: std::string title; std::string isbn; int pub_year; };
  • 151. Finding the most ancient book Moreover, min_element is wri+en so as to use operator < template <typename I> I min_element(I first, I last) { if (first == last) return last; I min = first; ++first; while (first != last) { if (*first < *min) min = first; ++first; } return min; }
  • 152. Less-than operator However, forcing the use of operator < seems an arbitrary choice template <typename I> I min_element(I first, I last) { if (first == last) return last; I min = first; ++first; while (first != last) { if (*first < *min) min = first; ++first; } return min; }
  • 153. Less-than operator This is evident if we use the func/onal nota/on3 of operator< template <typename I> I min_element(I first, I last) { if (first == last) return last; I min = first; ++first; while (first != last) { if (operator<(*first, *min)) min = first; ++first; } return min; } 3 With the caveat that such a nota/on is not possible when the value type of I is a built-in type
  • 154. Less-than operator In fact, operator< is just one out of many ordering criteria template <typename I> I min_element(I first, I last) { if (first == last) return last; I min = first; ++first; while (first != last) { if (operator<(*first, *min)) min = first; ++first; } return min; }
  • 155. A generalized version of min_element Therefore, the following looks like a be3er generaliza5on: template <typename I, typename C> I min_element(I first, I last, C cmp) { if (first == last) return last; I min = first; ++first; while (first != last) { if (cmp(*first, *min)) min = first; ++first; } return min; }
  • 156. On the nature of cmp Since cmp is invoked, one would say that cmp is a func%on if (cmp(*first, *min)) min = first;
  • 157. On the nature of cmp However, cmp is also passed as an input argument, therefore it also looks like an object template <typename I, typename C> I min_element(I first, I last, C cmp) { ... }
  • 158. On the nature of cmp
  • 159. Func%on object It turns out that cmp is an object that behaves like a func3on template <typename I, typename C> I min_element(I first, I last, C cmp) { ... }
  • 160. Func%on object We refer to such objects as func%on objects4 template <typename I, typename C> I min_element(I first, I last, C cmp) { ... } 4 Func'on objects are also called functors. However, we prefer not to use such a term, since outside the C++ community it is used to indicate a very different concept
  • 161. Func%on object In order to make an object look like a func3on we need to overload the call operator ()
  • 162. converter func. object class converter { public: converter(double er): exchange_rate(er) {} double operator()(double amount) const { return amount * exchange_rate; } private: double exchange_rate; };
  • 163. converter func. object Once ini'alized with the exchange rate, we can invoke the func'on object just like a plain func'on converter eur_to_usd(1.1); double euros; std::cin >> euros; std::cout << eur_to_usd(euros);
  • 164. The advantage of func. objects The advantage of func/on objects is that they can be efficiently passed to func/ons and consequently invoked template <typename I, typename C> I min_element(I first, I last, C cmp) { ... }
  • 165. Comparing books by pub_year In light of this, we need a func3on object that will take two books and verify if the first one is older than the second5 struct by_pub_year { bool operator()(book const& b1, book const& b2) const { return b1.pub_year() < b2.pub_year(); } }; 5 Here, we are assuming the existence of an access func5on named pub_year()
  • 166. Comparing books by pub_year With by_pub_year in place, we can finally look for the most ancient book std::vector<book> bs = ... auto m = min_element(bs.begin(), bs.end(), by_pub_year());
  • 167. Default comparison However, we would s-ll like to default to operator< when no custom func-on object is passed std::vector<book> bs = ... auto min_isbn = min_element(bs.begin(), bs.end());
  • 168. less func&on object To this extent, let us first write a func4on object to serve as the default comparator, which we call less6 struct less { template <typename T> // T is a totally ordered type bool operator(T const& e1, T const& e2) const { return e1 < e2; } }; 6 In the C++ Standard, the type parameteriza4on is on the class, rather than on the operator overload. That is, the standard default comparator is of type std::less<T>
  • 169. min_element overload Then, we provide an overload of min_element which wraps the more general func7on template <typename I, typename C> I min_element(I first, I last, C cmp) { ... }Β Β Β Β Β Β Β Β Β Β Β Β Β  template <typename I> I min_element(I first, I last) { return min_element(first, last, less()); }
  • 170. Finding the minimum book Thanks to this, we are free to decide if we want to pass or not a custom comparator std::vector<book> bs = ... auto min_isbn = min_element(bs.begin(), bs.end()); auto min_pub = min_element(bs.begin(), bs.end(), by_pub_year());
  • 171. Does by_pub_year induce a strict total order on books?
  • 172. py_pub_year vs. strict total order As a ma&er of fact, by_pub_year does not induce a strict total order struct by_pub_year { ... };
  • 173. py_pub_year vs. strict total order Indeed, the trichotomy law would impose two books with the same publishing date to be the same !by_pub_year({"The dubliners", 1914}, {"The metamorphosis ", 1914}) && !by_pub_year({"The metamorphosis ", 1914}, {"The dubliners", 1914})
  • 174. Equivalent rela-on No#ce that the property of having the same publishing date is an equivalent rela,on
  • 175. Equivalent classes As such, it par--ons the set of books into equivalent classes β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ * * β”‚ β”‚ β”‚ * β”‚ * 1851 * β”‚ * β”‚ β”‚ * β”‚ * * β”‚ * β”‚ β”‚ * │─────────────────────┬────────│ * β”‚ β”‚ β”‚ * β”‚ β”‚ β”‚ β”‚ β”‚ * 2005 * β”‚ * β”‚ 1712 β”‚ β”‚ 1987 β”‚ * * β”‚ β”‚ β”‚ β”‚ │──────────┬─────────── 2016 β”‚ * * β”‚ β”‚ * β”‚ β”‚ * β”‚ β”‚ β”‚ β”‚ * β”‚ * * β”‚ * β”‚ * * β”‚ β”‚ β”‚ * β”‚ β”‚ │────────┴────────── β”‚ β”‚ 1901 β”‚ 1301 β”‚ * * β”‚ β”‚ * β”‚ * * β”‚ β”‚ 1510 β”‚ β”‚ * * β”‚ * β”‚ * β”‚ * * β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • 176. Strict weak ordering A strict weak ordering is an ordering rela-on that is strict, transi/ve and obeys the weak-trichotomy law
  • 177. Weak-trichotomy law An ordering rela,on r obeys the weak-trichotomy law if !r(a, b) && !r(b, a) is the same as eq(a, b), for some equivalent rela0on eq
  • 178. Weak vs. total ordering Therefore, a strict total ordering is a par-cular case of weak total ordering in which equality is used as the equivalent rela-on
  • 179. min_element requirements Finally, we can state the correct requirements for min_element // I is a forward iterator // C defines a strict weak ordering on I's value type template <typename I, typename C> I min_element(I first, I last, C cmp) { ... }
  • 181. Generic programming The Standard Template Library is the most successful example of a programming paradigm called generic programming7 7 With the Boost library steadily holding the second posi5on
  • 182. Generic programming Generic programming is an approach to programming that focuses on designing algorithms and data structures so that they work in the most general se0ng without loss of efficiency
  • 183. Generic programming That is, generic programming is a way of developing so7ware that maximizes code reuse without sacrificing performance
  • 184. Generic programming Generic programming achieves this through parameteriza)on
  • 185. Parameteriza)on We can parameterize a type with another (such as a vector with its element type) template <typename T> class vector { ... }
  • 186. Parameteriza)on We can parameterize an algorithm with an other (such as the min_element func6on with a comparison func. object) template <typename I, typename C> I min_element(I first, I last, C cmp) {...}
  • 187. Polymorphism Non-generic func-ons are monomorphic, i.e., they operate on one data type int* min_element(int* first, int* last) {...}
  • 188. Polymorphism For example, the following non-generic version of min_element is specific to arguments of type int* int* min_element(int* first, int* last) {...}
  • 189. Polymorphism On the contrary, generic func1ons are polymorphic, i.e., they operate on any data type so long as their requirements hold // I is a forward iterator // C defines a strict weak ordering on I's value type template <typename I, typename C> I min_element(I first, I last, C cmp) {...}
  • 190. Parametric polymorphism This form of polymorphism is usually called parametric polymorphism, as opposed to ad-hoc polymorphism, which is typical of the object-oriented paradigm
  • 191. Most general algorithms Generic programming tries to discover polymorphic func6ons by observing that several monomorphic func6ons all share a similar structure
  • 192. Most general algorithms That is, generic programming tries to define algorithms in terms of the most general concepts
  • 193. Avoid par*al solu*ons The availability of correct generic algorithms allows developers to avoid wri7ng their own par$ally correct ones
  • 194. Avoid par*al solu*ons Thanks to this, developers can avoid using statements such as for and while that can cause non-robust behavior
  • 195. Avoid par*al solu*ons With min_element, we should not need any more to iterate over a container with a for loop just for the sake of finding the minimum element
  • 196. Avoid par*al solu*ons "Photoshop is roughly 3 million lines of code last 7me I counted, which means I think we will be able to express the en7re Photoshop in about 30 thousand lines of code" (S. Parent)
  • 197. Before using the STL void PanelBar::RepositionExpandedPanels(Panel* fixed_panel) { CHECK(fixed_panel); // First, find the index of the fixed panel. int fixed_index = GetPanelIndex(expanded_panels_, *fixed_panel); CHECK_LT(fixed_index, expanded_panels_.size()); // Next, check if the panel has moved to the other side of another panel. const int center_x = fixed_panel->cur_panel_center(); for (size_t i = 0; i < expanded_panels_.size(); ++i) { Panel* panel = expanded_panels_[i].get(); if (center_x <= panel->cur_panel_center() || i == expanded_panels_.size() - 1) { if (panel != fixed_panel) { // If it has, then we reorder the panels. ref_ptr<Panel> ref = expanded_panels_[fixed_index]; expanded_panels_.erase(expanded_panels_.begin() + fixed_index); if (i < expanded_panels_.size()) { expanded_panels_.insert(expanded_panels_.begin() + i, ref); } else { expanded_panels_.push_back(ref); } } break; } }
  • 198. A"er using the STL // Next, check if the panel has moved to the left side of another panel. auto f = begin(expanded_panels_) + fixed_index; auto p = lower_bound(begin(expanded_panels_), f, center_x, [](const ref_ptr<Panel>& e, int x){ return e->cur_panel_center() < x; }); // If it has, then we reorder the panels. rotate(p, f, f + 1);
  • 200. Bibliography β€’ B. Stroustrup, Programming: Principles and Prac8ce Using C++ (2nd ed.) β€’ A. Stepanov, P. McJones, Elements of programming β€’ A. Stepanov, D. Rose, From Mathema8cs to Generic Programming
  • 201. Bibliography β€’ A. Stepanov, Notes on programming β€’ A. Stepanov, Efficient Programming with Components Lecture 4 β€’ A. Stepanov, Efficient Programming with Components Lecture 11 β€’ S. Parent, A Possible Future of SoCware Development β€’ S. Parent, Programming ConversaEons Lecture 5 β€’ S. T. Lavavej, Standard Template Library (STL), 1 of n
  • 202. Bibliography β€’ B. Stroustrup, C++ in 2005 β€’ B. Stroustrup, What is "generic programming"? β€’ ISO C++, What's the big deal with generic programming?