Boost logo

Boost :

From: Greg Colvin (greg_at_[hidden])
Date: 2000-07-25 18:03:37


From: Beman Dawes <beman_at_[hidden]>
> Greg Colvin wrote:
>
> >But seriously, the trouble with template metaprogramming
> >is that the syntax was never designed for the purpose,
> >so it's just terrible to read and write.
>
> It really isn't so bad once you get used to it. A lot easier than trying
> to use partial specialization, for example. And it seems to be less
> sensitive to compiler quirks than might be expected.
>
> Read the book (or at least the C++ parts of it); don't jump to quickly to
> judgement. Try a little code. It really works.

I'm just too busy to read the book right now, but I have
been following these techniques ever since Erwin Unruh
showed us how to generate the prime numbers in the error
messages from compiling a template instantiation. At first
I was amused, then intrigued, then horrified.

I agree that these techniques are the best we have now,
and I'm not really serious about the macros, but I do
think that when we finish discovering all the unexpected
power of templates it will be time to come up with syntax
that better suits the purpose. A good discussion can be
found at:

http://extreme.indiana.edu/~tveldhui/papers/pepm99/

C++ Templates as Partial Evaluation
Todd L. Veldhuizen

Abstract:

This paper explores the relationship between C++ templates and partial
evaluation. Templates were designed to support generic programming but
unintentionally provided the ability to write code generators and
perform static computations. These features are accidental, and as a
result their syntax and semantics are awkward. Despite being unwieldy,
these techniques have become somewhat popular because they partially
solve an important problem in scientific computing- how to provide
libraries of domain-specific abstractions without performance loss. It
turns out that the C++ template mechanism is really partial evaluation
in disguise: C++ may be regarded as a two-level language in which types
are first-class values and template instantiation resembles offline
partial evaluation. That C++ templates have proven so useful
underscores the potential importance of partial evaluation as a
language feature.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk