dune-common  2.3.1
gcd.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_GCD_HH
4 #define DUNE_GCD_HH
5 
6 #include "static_assert.hh"
7 namespace Dune
8 {
18 #ifndef DOXYGEN
19 
22  template<long a, long b, bool bo>
23  struct GcdHelper
24  {};
25 
26 
27  template<long a, long b>
28  struct GcdHelper<a,b,true>
29  {
33  static void conceptCheck()
34  {
35  dune_static_assert(b<a, "b<a must hold!");
36  dune_static_assert(0<b, "b must be positive");
37  }
38 
39 
43  const static long gcd = GcdHelper<b,a%b,true>::gcd;
44  };
45 
46  template<long a, long b>
47  struct GcdHelper<a,b,false>
48  {
52  const static long gcd = GcdHelper<b,a,true>::gcd;
53  };
54  template<long a>
55  struct GcdHelper<a,0,true>
56  {
57  const static long gcd=a;
58  };
59 
60 #endif
61 
65  template<long a, long b>
66  struct Gcd
67  {
70  const static long value = GcdHelper<a,b,(a>b)>::gcd;
71  };
72 
76 }
77 
78 #endif