Lecture 5 - Page 5 : 39
Notes about C++
Templates and The Standard Library
* Templates
Templates
Templates versus generics in Java, C# and C++
Example - Point<C>
Class templates in C++
Example - Point<C,dim,default_value>
Function templates
Policies with Templates
Example of Policies with Templates
Template Specialization
Example - Specialization of Point<C> to Point<char>
Specialization of class templates - complete and partial
Compile time computations with template specialization
* Vector Basics
Vectors - basic use
* Iterators
Iterators seen as generalized pointers
Example uses of iterators - basis stuff
Different classifications of iterators
Categories of iterators
Insert iterators
* Standard Containers
Documentation of the container library
Overview of containers
A priority queue example
A map example
Common properties of containers
Container member types
A vector specialization: vector<bool>
* Algorithms
Documentation of the algorithms library
Overview of Algorithms
Principles used for algorithms
The for-each algorithm
Function objects
Using the sort algorithm
An example of for-each and function objects
Use of function objects in STL
Adapter examples
Class templates in C++
In many ways similar to generic classes in C# and Java
Template classes versus classes
A template can be used to create classes by means of
template instantiation
Template instantiation
Supplying actual template parameters
Template parameters to classes must be supplied explicitly
Each instantiation creates a class which has the same status as a hand crafted class
"The generated classes and functions are perfectly ordinary classes that obey all the usual rules for classes"
"... a powerful way of generating code"
"... a certain amount of caution is in order to avoid flooing memory with almost identical [...] definitions"
[Stoustrup page 331]
Type parameters are not related by inheritance
"There are no requirements that different arguments for the same template parameter should be related by inheritance"
, §13.2.1
No constraints on formal type parameters as in C#