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 and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 5 - Page 13 : 39
Notes about C++
Templates and The Standard Library
Compile time computations with template specialization

We show examples of simple recursive functions which can be called and evaluated by the compiler

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/templates/functions/fak/fak1.cppThe factorial function - from Wikipedia.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/templates/functions/pow/pow1.cppThe power function on integer type arguments.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/templates/functions/pow/pow1a.cppThe power function on integer type arguments - alternative implementation with an enumeration constant.


 

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/templates/functions/pow/pow3.cppA more advanced version of the power function - from Stack Overflow.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/templates/functions/pow/pow4.cppA variant of the more advanced version of the power function.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/templates/functions/pow/pow3-outputProgram 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