Lecture overview -- Keyboard shortcut: 'u'  Previous page: Specialization of class templates - complete and partial -- Keyboard shortcut: 'p'  Next page: Vector Basics [Section] -- Keyboard shortcut: 'n'  Lecture notes - all slides together  Annotated slide -- Keyboard shortcut: 't'  Alphabetic index  Help page about these notes  Course home    Templates and The Standard Library - slide 13 : 39

Compile time computations with template specialization
We show examples of simple recursive functions which can be called and evaluated by the compiler
fak1.cpp
The factorial function - from Wikipedia.
pow1.cpp
The power function on integer type arguments.
pow1a.cpp
The power function on integer type arguments - alternative implementation with an enumeration constant.
pow3.cpp
A more advanced version of the power function - from Stack Overflow.
pow4.cpp
A variant of the more advanced version of the power function.
pow3-output
Program output - both versions.

The 'functions' from above relies on the compiler's ability to evaluate constant expressions, see §C.5 in The C++ Programming Language