dune-common  2.2.0
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 {
00016 #ifndef DOXYGEN
00017 
00020   template<long a, long b, bool bo>
00021   struct GcdHelper
00022   {};
00023   
00024   
00025   template<long a, long b>
00026   struct GcdHelper<a,b,true>
00027   {
00031     static void conceptCheck()
00032     {
00033       dune_static_assert(b<a, "b<a must hold!");
00034       dune_static_assert(0<b, "b must be positive");
00035     }
00036 
00037     
00041      const static long gcd = GcdHelper<b,a%b,true>::gcd;
00042   };
00043   
00044   template<long a, long b>
00045   struct GcdHelper<a,b,false>
00046   {
00050     const static long gcd = GcdHelper<b,a,true>::gcd;
00051   };
00052   template<long a>
00053   struct GcdHelper<a,0,true>
00054   {
00055     const static long gcd=a;
00056   };
00057   
00058 #endif
00059   
00063   template<long a, long b>
00064   struct Gcd
00065   {
00068     const static long value = GcdHelper<a,b,(a>b)>::gcd;
00069   };
00070   
00074 }
00075 
00076 #endif