[Gllug] C++ Templates, Opinions?
Nix
nix at esperi.org.uk
Fri Dec 17 16:50:32 UTC 2004
On Fri, 17 Dec 2004, Bruce Richardson announced authoritatively:
> Using C++ templates is effectively like using a sophisticated
> preprocessor. This means that templates can allow you to avoid this
> trap but still have code reuse.
Sophisticated? It's Turing-complete!
I'd call it a macro-expander, not a preprocessor. You couldn't implement
C++ templating in any kind of preprocessor without reimplementing the
C++ parser in that preprocessor. (i.e., it can't be `pre'.)
> OTOH, templates are overused by former C-coders who don't really
> undestand OO and think it's all just a clever preprocessor hack.
IMHO, templates are underused by virtually everyone. C++ code written by
expert C++ programmers has template instantiations on virtually every
line (many of them uses of the standard library). Consult random posts
on comp.lang.c++.moderated for more examples than I can count. :)
I consider C++ a template-expansion language that happens to have
OO features as well. :)
> Then agaoin, there are some interesting things you can do with
> templates: http://en.wikipedia.org/wiki/Template_metaprogramming
Oh, Alexandescu is *smart*. Policy classes are a *genius* idea.
The only problem with template metaprogramming is that because
it wasn't actually an original design feature of C++, its
syntax is rather baroque and hard to read.
--
`The sword we forged has turned upon us
Only now, at the end of all things do we see
The lamp-bearer dies; only the lamp burns on.'
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list