]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/compare.hh
2003 -> 2004
[lilypond.git] / flower / include / compare.hh
1 /*
2   flowerlib
3
4   (c) 1996--2004 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     return function (t1, t2) op 0;\
13 }\
14
15 #define GPP_MINMAX_OPERATOR(type, op, opp) \
16 inline type \
17 operator op (type t1, type t2)\
18 {\
19      return (t1 opp t2) ? t1 :  t2;\
20 }\
21
22
23 #if defined (__GNUG__) && ! defined (__STRICT_ANSI__)
24 #define GPP_MINMAX(type, prefix)\
25        prefix GPP_MINMAX_OPERATOR (type, <?, <)\
26        prefix GPP_MINMAX_OPERATOR (type, >?, >)
27 #else
28 #define GPP_MINMAX(type, prefix)
29 #endif
30
31 /**  handy notations for a signed comparison. 
32     make the operators{<,<=,==,>=,>} and the MAX and MIN of two.
33     Please fill a & in the type argument if necessary.    
34     */
35 #define TEMPLATE_INSTANTIATE_COMPARE(type, function, prefix) \
36 prefix ONE_OPERATOR (type, function, >)\
37 prefix ONE_OPERATOR (type, function, >=)\
38 prefix ONE_OPERATOR (type, function, ==)\
39 prefix ONE_OPERATOR (type, function, !=)\
40 prefix ONE_OPERATOR (type, function, <)\
41 prefix ONE_OPERATOR (type, function, <=)\
42 GPP_MINMAX (type, prefix)\
43 prefix inline type max (type t1, type t2) {  return (t1 > t2)? t1 : t2; }\
44 prefix inline type min (type t1, type t2) {  return (t1 < t2)? t1 : t2; }\
45   \
46 prefix  bool operator< (type t1, type t2) /* stupid fix to allow ; */
47
48
49     
50 #define INSTANTIATE_COMPARE(type, func) TEMPLATE_INSTANTIATE_COMPARE (type,func,)
51      
52
53      
54 #endif
55