power10.hpp

Go to the documentation of this file.
00001 
00004 #ifndef POWER10_HPP_
00005 #define POWER10_HPP_
00006 
00007 template<int N>
00008 struct power10; // forward declaration
00009 
00011 template<int N>
00012 struct square
00013 {
00014   // A metaprogramming function to square a value.
00015   enum t { value = N * N };
00016 };
00017 
00023 template<int N, bool Even>
00024 struct power10_aux
00025 {
00026   // Primary template is for odd N (Even is false)
00027   enum t { value = 10 * power10<N - 1>::value };
00028 };
00029 
00034 template<int N>
00035 struct power10_aux<N, true>
00036 {
00037   // Specialization when N is even: square the value
00038   enum t { value = square<power10<N / 2>::value>::value };
00039 };
00040 
00047 template<int N>
00048 struct power10
00049 {
00050   enum t { value = power10_aux<N, N % 2 == 0>::value };
00051 };
00052 
00053 template<>
00054 struct power10<0>
00055 {
00056   enum t { value = 1 };
00057 };
00058 #endif

Generated on Sun Nov 30 09:53:22 2008 for Exploring C++ - Final Forms of Key Examples by  doxygen 1.5.3