00001
00002
00003 #ifndef DUNE_GCD_HH
00004 #define DUNE_GCD_HH
00005
00006 namespace Dune
00007 {
00017 #ifndef DOXYGEN
00018
00021 template<long a, long b, bool bo>
00022 struct GcdHelper
00023 {};
00024
00025
00026 template<long a, long b>
00027 struct GcdHelper<a,b,true>
00028 {
00032 static void conceptCheck()
00033 {
00034 static_assert(b<a, "b<a must hold!");
00035 static_assert(0<b, "b must be positive");
00036 }
00037
00038
00042 const static long gcd = GcdHelper<b,a%b,true>::gcd;
00043 };
00044
00045 template<long a, long b>
00046 struct GcdHelper<a,b,false>
00047 {
00051 const static long gcd = GcdHelper<b,a,true>::gcd;
00052 };
00053 template<long a>
00054 struct GcdHelper<a,0,true>
00055 {
00056 const static long gcd=a;
00057 };
00058
00059 #endif
00060
00064 template<long a, long b>
00065 struct Gcd
00066 {
00069 const static long value = GcdHelper<a,b,(a>b)>::gcd;
00070 };
00071
00075 }
00076
00077 #endif