From Generic Invocations to Generic Implementations
Conference contribution, 2006
Software performance benefits from executing computations
on constant data statically, at compile time. Unlike most languages, C++ allows expressing static computations by language means (template meta-programming), without relying on separate preprocessing tools.
However, static code differs from dynamic code by syntax and even by programming style, as the former is functional, the latter imperative. A library designer who wants to support both a static and a dynamic version of an algorithm is
therefore forced to design and maintain two implementations.
A common formulation is presented that allows one to implement an algorithm generically by a single definition, while encoding static parameter properties within the argument types. By the choice of argument representation, the user determines how the algorithm is evaluated. This decoupling preserves all information necessary to have the compiler create appropriate code for each case.
The realization by an ANSI C++ library of static constructs guarantees portability and allows an optimizing compiler to eliminate run-time overhead.