@@ -10,12 +10,14 @@ template < typename A, typename B > struct Compare
10
10
if (b<a) return 1 ;
11
11
return 0 ;
12
12
}
13
- inline static bool equal (const A &a,const B &b) { return (!(a < b)) && (!(b < a)); }
14
- inline static bool notEqual (const A &a,const B &b) { return (a<b) || (b<a); }
15
- inline static bool less (const A &a,const B &b) { return a<b; }
16
- inline static bool more (const A &a,const B &b) { return b<a; }
17
- inline static bool lessOrEqual (const A &a,const B &b) { return !(b<a); }
18
- inline static bool moreOrEqual (const A &a,const B &b) { return !(a<b); }
13
+ inline static bool equal (const A &a,const B &b) { return a==b; }
14
+ inline static bool notEqual (const A &a,const B &b) { return a!=b; }
15
+ inline static bool equivalent (const A &a,const B &b) { return (!(a < b)) && (!(b < a)); }
16
+ inline static bool notEquivalent (const A &a,const B &b) { return (a<b) || (b<a); }
17
+ inline static bool less (const A &a,const B &b) { return a<b; }
18
+ inline static bool more (const A &a,const B &b) { return b<a; }
19
+ inline static bool lessOrEqual (const A &a,const B &b) { return !(b<a); }
20
+ inline static bool moreOrEqual (const A &a,const B &b) { return !(a<b); }
19
21
};
20
22
21
23
// helpers for macros
@@ -57,59 +59,61 @@ inline static int arduinoCICompareBetween(const __FlashStringHelper * const &a,c
57
59
58
60
59
61
// this macro works for all the string-based comparisons
62
+ // note that it substitutes equivalence for equality
60
63
// but just in case, https://stackoverflow.com/a/13842784/2063546
61
- #define comparisonTemplateMacro (T1, T1m, T2, T2m, betweenImpl, ...) \
62
- template < __VA_ARGS__ > struct Compare <T1 T1m, T2 T2m>; \
63
- template < __VA_ARGS__ > struct Compare <T1 T1m, T2 T2m> \
64
- { \
65
- inline static int between ( T1 const (&a)T1m, T2 const (&b)T2m) { return betweenImpl; } \
66
- inline static bool equal ( T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) == 0 ; } \
67
- inline static bool notEqual ( T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) != 0 ; } \
68
- inline static bool less ( T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) < 0 ; } \
69
- inline static bool more ( T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) > 0 ; } \
70
- inline static bool lessOrEqual (T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) <= 0 ; } \
71
- inline static bool moreOrEqual (T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) >= 0 ; } \
64
+ #define eqComparisonTemplateMacro (T1, T1m, T2, T2m, betweenImpl, ...) \
65
+ template < __VA_ARGS__ > struct Compare <T1 T1m, T2 T2m>; \
66
+ template < __VA_ARGS__ > struct Compare <T1 T1m, T2 T2m> \
67
+ { \
68
+ inline static int between ( T1 const (&a)T1m, T2 const (&b)T2m) { return betweenImpl; } \
69
+ inline static bool equal ( T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) == 0 ; } \
70
+ inline static bool notEqual ( T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) != 0 ; } \
71
+ inline static bool equivalent ( T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) == 0 ; } \
72
+ inline static bool notEquivalent (T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) != 0 ; } \
73
+ inline static bool less ( T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) < 0 ; } \
74
+ inline static bool more ( T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) > 0 ; } \
75
+ inline static bool lessOrEqual ( T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) <= 0 ; } \
76
+ inline static bool moreOrEqual ( T1 const (&a)T1m, T2 const (&b)T2m) { return between (a, b) >= 0 ; } \
72
77
};
73
78
74
- comparisonTemplateMacro (String, , String, , a.compareTo(b))
75
- comparisonTemplateMacro (String, , const char *, , a.compareTo(b))
79
+ eqComparisonTemplateMacro (String, , String, , a.compareTo(b))
80
+ eqComparisonTemplateMacro (String, , const char *, , a.compareTo(b))
76
81
#if defined(F)
77
- comparisonTemplateMacro (String, , const __FlashStringHelper *, , arduinoCICompareBetween(a, b))
78
- comparisonTemplateMacro (const char *,, const __FlashStringHelper *, , strcmp_P(a,(const char *)b))
79
- comparisonTemplateMacro (const __FlashStringHelper *, , String, , -arduinoCICompareBetween(b, a))
80
- comparisonTemplateMacro (const __FlashStringHelper *, , const char *, , -strcmp_P(b,(const char *)a))
81
- comparisonTemplateMacro (const __FlashStringHelper *, , const __FlashStringHelper *, , arduinoCICompareBetween(a, b))
82
- comparisonTemplateMacro (const __FlashStringHelper *, , char *, , -strcmp_P(b,(const char *)a))
83
- comparisonTemplateMacro (char *, , const __FlashStringHelper *, , strcmp_P(a,(const char *)b))
84
- comparisonTemplateMacro (const __FlashStringHelper *, , char , [M], -strcmp_P(b,(const char *)a), size_t M)
85
- comparisonTemplateMacro (char , [N], const __FlashStringHelper *, , strcmp_P(a,(const char *)b), size_t N)
82
+ eqComparisonTemplateMacro (String, , const __FlashStringHelper *, , arduinoCICompareBetween(a, b))
83
+ eqComparisonTemplateMacro (const char *,, const __FlashStringHelper *, , strcmp_P(a,(const char *)b))
84
+ eqComparisonTemplateMacro (const __FlashStringHelper *, , String, , -arduinoCICompareBetween(b, a))
85
+ eqComparisonTemplateMacro (const __FlashStringHelper *, , const char *, , -strcmp_P(b,(const char *)a))
86
+ eqComparisonTemplateMacro (const __FlashStringHelper *, , const __FlashStringHelper *, , arduinoCICompareBetween(a, b))
87
+ eqComparisonTemplateMacro (const __FlashStringHelper *, , char *, , -strcmp_P(b,(const char *)a))
88
+ eqComparisonTemplateMacro (char *, , const __FlashStringHelper *, , strcmp_P(a,(const char *)b))
89
+ eqComparisonTemplateMacro (const __FlashStringHelper *, , char , [M], -strcmp_P(b,(const char *)a), size_t M)
90
+ eqComparisonTemplateMacro (char , [N], const __FlashStringHelper *, , strcmp_P(a,(const char *)b), size_t N)
86
91
#endif
87
- comparisonTemplateMacro (String, , char *, , a.compareTo(b))
88
- comparisonTemplateMacro (const char *, , String, , -b.compareTo(a))
89
- comparisonTemplateMacro (const char *, , const char *, , strcmp(a,b))
90
- comparisonTemplateMacro (const char *, , char *, , strcmp(a,b))
91
- comparisonTemplateMacro (char *, , String, , -b.compareTo(a))
92
- comparisonTemplateMacro (char *, , const char *, , strcmp(a,b))
93
- comparisonTemplateMacro (char *, , char *, , strcmp(a,b))
94
- comparisonTemplateMacro (String, , char , [M], a.compareTo(b), size_t M)
95
- comparisonTemplateMacro (const char *, , char , [M], strcmp(a,b), size_t M)
96
- comparisonTemplateMacro (char *, , char , [M], strcmp(a,b), size_t M)
97
- comparisonTemplateMacro (char , [N], String, , -b.compareTo(a), size_t N)
98
- comparisonTemplateMacro (char , [N], const char *, , strcmp(a,b), size_t N)
99
- comparisonTemplateMacro (char , [N], char *, , strcmp(a,b), size_t N)
100
- comparisonTemplateMacro (char , [N], char , [M], strcmp(a,b), size_t N, size_t M)
92
+ eqComparisonTemplateMacro (String, , char *, , a.compareTo(b))
93
+ eqComparisonTemplateMacro (const char *, , String, , -b.compareTo(a))
94
+ eqComparisonTemplateMacro (const char *, , const char *, , strcmp(a,b))
95
+ eqComparisonTemplateMacro (const char *, , char *, , strcmp(a,b))
96
+ eqComparisonTemplateMacro (char *, , String, , -b.compareTo(a))
97
+ eqComparisonTemplateMacro (char *, , const char *, , strcmp(a,b))
98
+ eqComparisonTemplateMacro (char *, , char *, , strcmp(a,b))
99
+ eqComparisonTemplateMacro (String, , char , [M], a.compareTo(b), size_t M)
100
+ eqComparisonTemplateMacro (const char *, , char , [M], strcmp(a,b), size_t M)
101
+ eqComparisonTemplateMacro (char *, , char , [M], strcmp(a,b), size_t M)
102
+ eqComparisonTemplateMacro (char , [N], String, , -b.compareTo(a), size_t N)
103
+ eqComparisonTemplateMacro (char , [N], const char *, , strcmp(a,b), size_t N)
104
+ eqComparisonTemplateMacro (char , [N], char *, , strcmp(a,b), size_t N)
105
+ eqComparisonTemplateMacro (char , [N], char , [M], strcmp(a,b), size_t N, size_t M)
101
106
102
- comparisonTemplateMacro (A, , std::nullptr_t , , a ? 1 : 0 , typename A)
103
- comparisonTemplateMacro (std::nullptr_t , , B, , b ? -1 : 0 , typename B)
107
+ eqComparisonTemplateMacro (A, , std::nullptr_t , , a ? 1 : 0 , typename A)
108
+ eqComparisonTemplateMacro (std::nullptr_t , , B, , b ? -1 : 0 , typename B)
104
109
105
110
// super general comparisons
106
- template <typename A, typename B> int compareBetween( const A &a, const B &b) { return Compare<A, B>::between ( a, b); }
107
- template <typename A, typename B> bool compareEqual ( const A &a, const B &b) { return Compare<A, B>::equal ( a, b); }
108
- template <typename A, typename B> bool compareNotEqual ( const A &a, const B &b) { return Compare<A, B>::notEqual ( a, b); }
109
- template <typename A, typename B> bool compareLess ( const A &a, const B &b) { return Compare<A, B>::less ( a, b); }
110
- template <typename A, typename B> bool compareMore ( const A &a, const B &b) { return Compare<A, B>::more ( a, b); }
111
- template <typename A, typename B> bool compareLessOrEqual (const A &a, const B &b) { return Compare<A, B>::lessOrEqual (a, b); }
112
- template <typename A, typename B> bool compareMoreOrEqual (const A &a, const B &b) { return Compare<A, B>::moreOrEqual (a, b); }
113
-
114
- template <typename A, typename B> bool evaluateDoubleEqual (const A &a, const B &b) { return a == b; }
115
- template <typename A, typename B> bool evaluateNotEqual ( const A &a, const B &b) { return a != b; }
111
+ template <typename A, typename B> int compareBetween( const A &a, const B &b) { return Compare<A, B>::between ( a, b); }
112
+ template <typename A, typename B> bool compareEqual ( const A &a, const B &b) { return Compare<A, B>::equal ( a, b); }
113
+ template <typename A, typename B> bool compareNotEqual ( const A &a, const B &b) { return Compare<A, B>::notEqual ( a, b); }
114
+ template <typename A, typename B> bool compareEquivalent ( const A &a, const B &b) { return Compare<A, B>::equivalent ( a, b); }
115
+ template <typename A, typename B> bool compareNotEquivalent (const A &a, const B &b) { return Compare<A, B>::notEquivalent (a, b); }
116
+ template <typename A, typename B> bool compareLess ( const A &a, const B &b) { return Compare<A, B>::less ( a, b); }
117
+ template <typename A, typename B> bool compareMore ( const A &a, const B &b) { return Compare<A, B>::more ( a, b); }
118
+ template <typename A, typename B> bool compareLessOrEqual ( const A &a, const B &b) { return Compare<A, B>::lessOrEqual ( a, b); }
119
+ template <typename A, typename B> bool compareMoreOrEqual ( const A &a, const B &b) { return Compare<A, B>::moreOrEqual ( a, b); }
0 commit comments