Dune Core Modules (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"
7namespace Dune
8{
18#ifndef DOXYGEN
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
#define dune_static_assert(COND, MSG)
Helper template so that compilation fails if condition is not true.
Definition: static_assert.hh:79
Dune namespace.
Definition: alignment.hh:14
Fallback implementation of the C++0x static_assert feature.
Calculator of the greatest common divisor.
Definition: gcd.hh:67
static const long value
The greatest common divisior of a and b.
Definition: gcd.hh:70
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)