Tuesday, September 28, 2010

Compile-time Calculations via Templates

Compile-time calculations via templates use recursion instead of iteration, because compile-time values are immutable. New names are used instead of the same names having their values changed.

Reference: Modern C++ Design by Andrei Alexandrescu. Addison-Wesley, 2001, p.54

Many times an enum value is calculated via a previous enum value. It can be shown that this "generic meta-programming" is Turing Complete, which means in theory, it can basically compute what a typical computer could compute. In reality, the recursion is limited to a certain number of times.

No comments:

Post a Comment