]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/compare.hh
f2cff8a80f11ee4a1a03f0b9c68e60e5045321da
[lilypond.git] / flower / include / compare.hh
1 /*
2   flowerlib
3
4   (c) 1996--2007 Han-Wen Nienhuys
5 */
6 #ifndef COMPARE_HH
7 #define COMPARE_HH
8
9 #define ONE_OPERATOR(type, function, op)        \
10   inline bool                                   \
11   operator op (type t1, type t2)                \
12   {                                             \
13     return function (t1, t2) op 0;              \
14   }
15
16 /**  handy notations for a signed comparison.
17      make the operators{<,<=,==,>=,>} and the MAX and MIN of two.
18      Please fill a & in the type argument if necessary.
19 */
20 #define TEMPLATE_INSTANTIATE_COMPARE(type, function, prefix)            \
21   prefix ONE_OPERATOR (type, function, >)                               \
22     prefix ONE_OPERATOR (type, function, >=)                            \
23     prefix ONE_OPERATOR (type, function, ==)                            \
24     prefix ONE_OPERATOR (type, function, !=)                            \
25     prefix ONE_OPERATOR (type, function, <)                             \
26     prefix ONE_OPERATOR (type, function, <=)                            \
27     /* namespace std { */                                               \
28     prefix inline type max (type t1, type t2) { return (t1 > t2) ? t1 : t2; } \
29     prefix inline type min (type t1, type t2) { return (t1 < t2) ? t1 : t2; } \
30   /* } */                                                               \
31   /* stupid fix to allow ; */                                           \
32   prefix bool operator < (type t1, type t2)
33
34 #define INSTANTIATE_COMPARE(type, func) TEMPLATE_INSTANTIATE_COMPARE (type, func,)
35
36 #endif
37