In class today, the following topics were covered:
- a derivation of why mergesort is O(n*log2(n))
- the notion behind function templating in C++ and why templating can be useful
- syntax for templating
- examples of using templating to “abstract algorithms” such as binarySearch and mergeSort
- limitations on templating - that to use a type with a templated function, all operations (operators and functions) applied to the data in the templated function must be defined for the type attempting to be used.
Here are the examples we saw: templated searching, templated merge sorting (cpp version), templated merge sort (assembly language version)
Function templates are covered in Section 16.1 of the book. Self-test exercises 1 and 2 of that section (answers on page 720) are useful for getting more practice with function templating.