dune-common 2.1.1
gcd.hh
Go to the documentation of this file.
00001 #ifndef DUNE_GCD_HH
00002 #define DUNE_GCD_HH
00003 
00004 #include"static_assert.hh"
00005 namespace Dune
00006 {
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       dune_static_assert(b<a, "b<a must hold!");
00035       dune_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