JohnQ wrote:
....
To me, "templates" means the kind of thing the preprocessor does (text
substitution) and using it to generate typed code.
That's only one of the things that templates are about.
C++ templates allow you to:
Change behaviour for different types.
Compute compile time constants (like find first set bit) etc.
Force compile time errors when various assumptions are invalid.
Allows extensibility by the application through overloading and
specialization.
.... just to name a few ...
Macros are almost impossible to debug because of the way they work. It
is surprising that after so many years of using the preprocessor,
debuggers can't single step through macros but alas, they can't. C++
templates however are well supported by debuggers in comparison.
While you may like to think of templates as a facncy pre-processor, in
C++ templates are a more substantial and provide a "meta programmming"
paradigm.
As I explained earlier, one example where it worked by simplification of
the code was the mapping of types to ints for reading DXF files.
Without templates, it would have been very tedious to map 1000+
operations. With C++ templates, it was cut-paste relevant table in the
docs, decorate it with a few templates, viola. Extensibility is easy as
well because as the file format expands, there is a direct correlation
to the docs and so it will be simply a matter of adding a few more types
to the header file.
If you want to talk about C++ the standard (which is what we do here),
you need to understand that templates are a more extensive meta
programming feature. While you yourself may not want to use it, it is
part of the standard and is used in a much more extensive way.