Indiana University Bloomington

Luddy School of Informatics, Computing, and Engineering

Technical Report TR519:
C++ Templates as Partial Evaluation

Todd L. Veldhuizen
(Nov 1998), 6 pages pages
[Revised July 2000]
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.

Available as: