Generic Programming

Steven J. Zeil

Old Dominion University, Dept. of Computer Science

Table of Contents

1. Iterators + Templates = Generic Programming
1.1. Working with Iterators
1.2. Using std::copy
1.3. copy and I/O iterators
1.4. Copying, Overwriting, and Inserting
1.5. Some Useful Generic Functions
2. Passing Functions as Parameters
2.1. Function Types
2.2. Generics That Take Functions
3. Functors
3.1. Example: Functors and User Interface Programming
3.2. operator()
3.3. A Predicate Functor
3.4. Why Do Functors Work Where Functions Are Expected?
3.5. Functors Can Have Memory
3.6. std Functors for Comparisons
3.7. Substituting Your Own Comparison Functions
4. References

When we combine iterators with template functions, we get an powerful tool for writing programs. Because the iterator interface is the same no matter what kind of container the data is really in, many algorithms can be written as function templates to work with data in almost any kind of container.

This combination is called generic programming.

In the Forum:

(no threads at this time)