Kurt Nørmark
Department of Computer Science, Aalborg University
Abstract Previous lecture Next lecture Index References Contents | ... |
Templates |
Templates Slide Annotated slide Contents Index References |
|
|
|
Templates versus generics in Java, C# and C++ Slide Annotated slide Contents Index References |
|
|
|
Example - Point<C> Slide Annotated slide Contents Index References |
|
Program: A type parameterized variant of class Point - point.h. |
|
Program: The implementation of the template class Point - point.cc. |
|
Program: A program that illustrate template instantiation. |
|
|
Exercise 5.2. A template class with friends | Arrange that operator<< becomes a friend of the template class Point<C>. It may be useful to consult §C.13.2 page 854-855 in The C++ Programming Language. |
Class templates in C++ Slide Annotated slide Contents Index References |
|
|
Example - Point<C,dim,default_value> Slide Annotated slide Contents Index References |
|
Program: A type parameterized variant of class Point - point.h. |
|
Program: The implementation of the template class Point - point.cc. |
|
Program: A program that illustrate the template instantiation. |
|
|
Function templates Slide Annotated slide Contents Index References |
|
Program: The template function compare, and various uses of it. |
|
|
Program: Class Point with comparison operator friends. |
|
Program: The implementation of class Point. |
|
Program: The template function compare used for Point comparison. |
|
|
Policies with Templates Slide Annotated slide Contents Index References |
|
|
|
|
Example of Policies with Templates Slide Annotated slide Contents Index References |
|
Program: The Point class definition - a template - policy parameterized. |
|
Program: Member functions in class Point. |
|
Program: Four different policy classes - with type parameterized static methods. |
|
Program: A sample application. |
|
|
Program: The Point class definition - not a template in this version. |
|
Program: Member functions in class Point - not essential to this example. |
|
Program: Four different policy classes - with type parameterized static methods. |
|
Program: A sample application - together with policy parameterized functions. |
|
Template Specialization Slide Annotated slide Contents Index References |
|
|
|
|
|
Example - Specialization of Point<C> to Point<char> Slide Annotated slide Contents Index References |
|
Program: The general class template Point followed by the specialized one. |
|
Program: The implementation of the template class Point - point.cc - nothing interesting here. |
|
Program: A program that illustrate the instantiation of both the general and specialized template classes. |
|
Specialization of class templates - complete and partial Slide Annotated slide Contents Index References |
|
Program: Full and partial specializations of a class template A. |
|
Compile time computations with template specialization Slide Annotated slide Contents Index References |
|
Program: The factorial function - from Wikipedia. |
|
Program: The power function on integer type arguments. |
|
Program: The power function on integer type arguments - alternative implementation with an enumeration constant. |
|
|
Program: A more advanced version of the power function - from Stack Overflow. |
|
Program: A variant of the more advanced version of the power function. |
|
Program: Program output - both versions. |
|
|
Vector Basics |
Vectors - basic use Slide Annotated slide Contents Index References |
|
|
Iterators |
Iterators seen as generalized pointers Slide Annotated slide Contents Index References |
|
|
|
|
Example uses of iterators - basis stuff Slide Annotated slide Contents Index References |
|
Program: A really simple example of iterators. |
|
Program: The same program using a reverse iterator. |
|
Different classifications of iterators Slide Annotated slide Contents Index References |
|
|
|
Categories of iterators Slide Annotated slide Contents Index References |
|
|
|
|
|
Insert iterators Slide Annotated slide Contents Index References |
|
|
Program: Output insert-iterators and factory functions that create such iterators. |
|
Standard Containers |
Documentation of the container library Slide Annotated slide Contents Index References |
|
|
Overview of containers Slide Annotated slide Contents Index References |
|
|
|
|
A priority queue example Slide Annotated slide Contents Index References |
|
|
Program: Class point with an overloaded operator<. |
|
Program: The implementation of class Point and in particular operator<. |
|
Program: Illustration of priority_queue<Point, deque<Point> >. |
|
A map example Slide Annotated slide Contents Index References |
|
Program: Illustration of the map standard container. |
|
Program: Sample program input - provided via input redirection. |
|
Program: Program output. |
|
Common properties of containers Slide Annotated slide Contents Index References |
|
|
|
|
Container member types Slide Annotated slide Contents Index References |
|
|
|
Program: Illustration of the use of member types for a list of chars. |
|
Program: Same program - now with use of typename as prefix of 'nested dependent type names'. |
|
Program: Illustration of a couple of ambiguities. |
|
Program: Compiler error messages. |
|
Program: Ambiguities resolved. |
|
A vector specialization: vector<bool> Slide Annotated slide Contents Index References |
|
|
Program: Illustration of the use of vector<bool>. |
|
Algorithms |
Documentation of the algorithms library Slide Annotated slide Contents Index References |
|
Overview of Algorithms Slide Annotated slide Contents Index References |
|
|
|
Principles used for algorithms Slide Annotated slide Contents Index References |
|
|
The for-each algorithm Slide Annotated slide Contents Index References |
|
Program: A possible implementation of the for-each algorithm. |
|
Program: Implementation and sample use of for-each on an C-style array. |
|
Program: Implementation and sample use of for-each on a list of integers. |
|
|
Function objects Slide Annotated slide Contents Index References |
|
|
Program: Class Point with overloadings of the application operator. |
|
Program: Definition of Point application operators. |
|
Program: Sample uses of the application operators - Funny and artificial. |
|
|
Program: Class Point with another overloading of the application operator. |
|
Program: Definition of then Point application operator. |
|
Program: Sample uses of the application operators - slightly more realistic. |
|
Using the sort algorithm Slide Annotated slide Contents Index References |
|
Program: Two overloads of the sort function template. |
|
Program: Sorting a vector of integers. |
|
An example of for-each and function objects Slide Annotated slide Contents Index References |
|
Program: A possible use of for-each to solve this problem. |
|
|
Program: Following the advice: Solve the problem with a more appropriate algorithm. |
|
|
Program: The type greater and its base class. |
|
Use of function objects in STL Slide Annotated slide Contents Index References |
|
|
|
Adapter examples Slide Annotated slide Contents Index References |
|
Program: An illustration of plus<double>. |
|
Program: A possible definition of plus. |
|
Program: Another definition of plus - as a function template. |
|
Program: Use of member function adaption, with mem_fun_ref. |
|
Program: The definition of Point - point.h. |
|
Collected references Contents Index |
|
Chapter 5: Templates and The Standard Library
Course home Author home About producing this web Previous lecture (top) Next lecture (top) Previous lecture (bund) Next lecture (bund)
Generated: March 26, 2013, 13:03:51