The following code example is taken from the book
C++ Templates - The Complete Guide
by David Vandevoorde and Nicolai M. Josuttis, Addison-Wesley, 2002
© Copyright David Vandevoorde and Nicolai M. Josuttis 2002
#ifndef POW3_HPP
#define POW3_HPP
// primary template to compute 3 to the Nth
template<int N>
class Pow3 {
public:
enum { result = 3 * Pow3<N-1>::result };
};
// full specialization to end the recursion
template<>
class Pow3<0> {
public:
enum { result = 1 };
};
#endif // POW3_HPP