00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #pragma once
00015 #ifndef ConstPower_h__
00016 #define ConstPower_h__
00017
00019
00021 template <unsigned arg, unsigned exp>
00022 struct ConstPower
00023 {
00024 static enum
00025 {
00026 ans = ConstPower < arg, exp /2 >::ans * ConstPower < arg, exp /2 >::ans * ((exp%2 == 0) ? 1 : arg)
00027 };
00028 };
00029
00030 template < unsigned arg>
00031 struct ConstPower < arg, 0>
00032 {
00033 static enum
00034 {
00035 ans = 1
00036 };
00037 };
00038
00040
00042 template < unsigned arg, unsigned exp >
00043 struct TestConstPower
00044 {
00045 static enum
00046 {
00047 intermediate = ConstPower < arg, exp>::ans * TestConstPower<arg, exp - 1 >::intermediate,
00048 ans = (intermediate == ConstPower < arg, (ConstPower < exp, 2 >::ans + exp)/2>::ans) && TestConstPower<arg - 1,
00049 exp >::ans
00050 };
00051 };
00052
00053 template < unsigned arg >
00054 struct TestConstPower < arg, 0 >
00055 {
00056 static enum
00057 {
00058 intermediate = ConstPower < arg, 0 >::ans,
00059 ans = (intermediate == 1)
00060 };
00061 };
00062
00063 template < unsigned exp >
00064 struct TestConstPower < 1, exp >
00065 {
00066 static enum
00067 {
00068 intermediate = ConstPower < 1, exp >::ans,
00069 ans = (intermediate == 1)
00070 };
00071 };
00072
00073 template <>
00074 struct TestConstPower < 1, 0 >
00075 {
00076 static enum
00077 {
00078 intermediate = ConstPower < 1, 0 >::ans,
00079 ans = (intermediate == 1)
00080 };
00081 };
00082
00083
00084 #endif // ConstPower_h__