dune-common  2.2.1
gcd.hh
Go to the documentation of this file.
1 #ifndef DUNE_GCD_HH
2 #define DUNE_GCD_HH
3 
4 #include"static_assert.hh"
5 namespace Dune
6 {
16 #ifndef DOXYGEN
17 
20  template<long a, long b, bool bo>
21  struct GcdHelper
22  {};
23 
24 
25  template<long a, long b>
26  struct GcdHelper<a,b,true>
27  {
31  static void conceptCheck()
32  {
33  dune_static_assert(b<a, "b<a must hold!");
34  dune_static_assert(0<b, "b must be positive");
35  }
36 
37 
41  const static long gcd = GcdHelper<b,a%b,true>::gcd;
42  };
43 
44  template<long a, long b>
45  struct GcdHelper<a,b,false>
46  {
50  const static long gcd = GcdHelper<b,a,true>::gcd;
51  };
52  template<long a>
53  struct GcdHelper<a,0,true>
54  {
55  const static long gcd=a;
56  };
57 
58 #endif
59 
63  template<long a, long b>
64  struct Gcd
65  {
68  const static long value = GcdHelper<a,b,(a>b)>::gcd;
69  };
70 
74 }
75 
76 #endif