1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/*
* Copyright (C) 2007-2008 Xagasoft, All rights reserved.
*
* This file is part of the libbu++ library and is released under the
* terms of the license contained in the file LICENSE.
*/
#ifndef BU_UTIL_H
#define BU_UTIL_H
/* I borrowed this from someone who borrowed it from glib who borrowed it
* from...
*/
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
#define DEPRECATED __attribute__((__deprecated__))
#else
#define DEPRECATED
#endif /* __GNUC__ */
namespace Bu
{
template<typename item>
void swap( item &a, item &b )
{
item tmp = a;
a = b;
b = tmp;
}
template<typename item>
const item &min( const item &a, const item &b )
{
return a<b?a:b;
}
template<typename item>
item &min( item &a, item &b )
{
return a<b?a:b;
}
template<typename item>
const item &max( const item &a, const item &b )
{
return a>b?a:b;
}
template<typename item>
item &max( item &a, item &b )
{
return a>b?a:b;
}
template<typename item>
const item &mid( const item &a, const item &b, const item &c )
{
return min( max( a, b ), c );
}
template<typename item>
item &mid( item &a, item &b, item &c )
{
return min( max( a, b ), c );
}
//
// Basic comparison functors
//
template<typename item>
struct __basicLTCmp
{
bool operator()( const item &a, const item &b )
{
return a < b;
}
};
template<typename item>
struct __basicGTCmp
{
bool operator()( const item &a, const item &b )
{
return a > b;
}
};
template<typename item>
struct __basicPtrLTCmp
{
bool operator()( const item &a, const item &b )
{
return *a < *b;
}
};
template<typename item>
struct __basicPtrGTCmp
{
bool operator()( const item &a, const item &b )
{
return *a > *b;
}
};
};
#endif
|