00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #pragma once
00015 #ifndef ConstLog2_h__
00016 #define ConstLog2_h__
00017
00019
00022
00023 template <unsigned exp>
00024 struct ConstLog2
00025 {
00026 static enum
00027 {
00028 ans = ConstLog2 < exp /2 >::ans+1
00029 };
00030 };
00031
00032 template <>
00033 struct ConstLog2<1>
00034 {
00035 static enum
00036 {
00037 ans = 0
00038 };
00039 };
00040
00041 template <>
00042 struct ConstLog2<0>
00043 {
00044 static enum
00045 {
00046 ans = 0
00047 };
00048 };
00050 template <unsigned RANGE>
00051 struct TestConstLog2
00052 {
00053 static enum
00054 {
00055 ans = ((RANGE >> ConstLog2<RANGE>::ans) == 1) && TestConstLog2< RANGE - 1 >::ans
00056 };
00057 };
00058
00059 template <>
00060 struct TestConstLog2<1>
00061 {
00062 static enum
00063 {
00064 ans = ((1 >> ConstLog2<1>::ans) == 1) && (ConstLog2<0>::ans == 0)
00065 };
00066 };
00067
00068
00069 #endif // ConstLog2_h__