Have people found more interesting uses for metatemplate programming? I have mostly used it for determining constants at compile time rather than run-rime.
For those not familiar what this is:
Code:
#include <iostream>
template< unsigned N > struct tmplFactorial
{
enum { val = N * tmplFactorial< N-1 >::val };
};
template<> struct tmplFactorial< 1 >
{
enum { val = 1 };
};
#define mt_Factorial( n ) tmplFactorial< n >::val;
int main()
{
int x = mt_Factorial(6);
std::cout << "Factorial(6)=" << x << std::endl;
return 0;
}
Sample metatemplate program to generate the value of factorial(6) at compile time. Very useful if you expect parameters to change at compile time.