waterfall
0.2dev
Main Page
Related Pages
Classes
Files
File List
All
Classes
Files
Functions
Variables
Enumerations
Enumerator
Pages
src
utils.h
Go to the documentation of this file.
1
9
#ifndef UTILS_Q7Z8RACX
10
#define UTILS_Q7Z8RACX
11
12
13
#include <utility>
14
using namespace
std;
15
16
#include <cppapp/cppapp.h>
17
18
19
#ifdef NDEBUG
20
# define safeAdd(a, b) ((a) + (b))
21
# define safeMul(a, b) ((a) * (b))
22
#else
23
template
<
class
T>
24
T safeAdd(T a, T b)
25
{
26
T c = a + b;
27
28
if
(b > 0 ? c < a : c > a) {
29
LOG_ERROR(
"Addition overflow: "
<< a <<
" + "
<< b <<
" = "
<< c);
30
}
31
32
return
c;
33
}
34
35
template
<
class
T>
36
T safeMul(T a, T b)
37
{
38
T c = a * b;
39
40
return
c;
41
}
42
#endif
43
44
45
template
<
class
T>
46
pair<T, T> orderPair(T a, T b)
47
{
48
if
(a > b)
49
return
make_pair(b, a);
50
return
make_pair(a, b);
51
}
52
53
54
#define ORDER_PAIR(a, b) { \
55
if ((a) > (b)) { \
56
VAR(temp__, (a)); \
57
(a) = (b); \
58
(b) = temp__; \
59
} \
60
}
61
62
63
#endif
/* end of include guard: UTILS_Q7Z8RACX */
64
Generated on Fri Jan 31 2014 14:27:03 for waterfall by
1.8.4