Skip to content

Commit a65f6b1

Browse files
committed
allow compare of bool values
1 parent 598834a commit a65f6b1

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

cpp/unittest/Compare.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,99 @@ template < long N, long M > struct Compare<char [N],char [M]>
325325
return between(a,b) >= 0;
326326
} // moreOrEqual
327327
};
328+
template < > struct Compare<bool, bool>
329+
{
330+
inline static int between(bool a, bool b)
331+
{
332+
return b ? (a ? 0 : -1) : (a ? 1 : 0);
333+
} // between
334+
inline static bool equal(bool a, bool b)
335+
{
336+
return between(a,b) == 0;
337+
} // equal
338+
inline static bool notEqual(bool a, bool b)
339+
{
340+
return between(a,b) != 0;
341+
} // notEqual
342+
inline static bool less(bool a, bool b)
343+
{
344+
return between(a,b) < 0;
345+
} // less
346+
inline static bool more(bool a, bool b)
347+
{
348+
return between(a,b) > 0;
349+
} // more
350+
inline static bool lessOrEqual(bool a, bool b)
351+
{
352+
return between(a,b) <= 0;
353+
} // lessOrEqual
354+
inline static bool moreOrEqual(bool a, bool b)
355+
{
356+
return between(a,b) >= 0;
357+
} // moreOrEqual
358+
};
359+
template <typename T> struct Compare<bool, T>
360+
{
361+
inline static int between(bool a, T b)
362+
{
363+
return b ? (a ? 0 : -1) : (a ? 1 : 0);
364+
} // between
365+
inline static bool equal(bool a, T b)
366+
{
367+
return between(a,b) == 0;
368+
} // equal
369+
inline static bool notEqual(bool a, T b)
370+
{
371+
return between(a,b) != 0;
372+
} // notEqual
373+
inline static bool less(bool a, T b)
374+
{
375+
return between(a,b) < 0;
376+
} // less
377+
inline static bool more(bool a, T b)
378+
{
379+
return between(a,b) > 0;
380+
} // more
381+
inline static bool lessOrEqual(bool a, T b)
382+
{
383+
return between(a,b) <= 0;
384+
} // lessOrEqual
385+
inline static bool moreOrEqual(bool a, T b)
386+
{
387+
return between(a,b) >= 0;
388+
} // moreOrEqual
389+
};
390+
template <typename T> struct Compare<T, bool>
391+
{
392+
inline static int between(T a, bool b)
393+
{
394+
return b ? (a ? 0 : -1) : (a ? 1 : 0);
395+
} // between
396+
inline static bool equal(T a, bool b)
397+
{
398+
return between(a,b) == 0;
399+
} // equal
400+
inline static bool notEqual(T a, bool b)
401+
{
402+
return between(a,b) != 0;
403+
} // notEqual
404+
inline static bool less(T a, bool b)
405+
{
406+
return between(a,b) < 0;
407+
} // less
408+
inline static bool more(T a, bool b)
409+
{
410+
return between(a,b) > 0;
411+
} // more
412+
inline static bool lessOrEqual(T a, bool b)
413+
{
414+
return between(a,b) <= 0;
415+
} // lessOrEqual
416+
inline static bool moreOrEqual(T a, bool b)
417+
{
418+
return between(a,b) >= 0;
419+
} // moreOrEqual
420+
};
328421
template <typename A, typename B> int compareBetween(const A &a, const B &b) { return Compare<A,B>::between(a,b); }
329422
template <typename A, typename B> bool compareEqual(const A &a, const B &b) { return Compare<A,B>::equal(a,b); }
330423
template <typename A, typename B> bool compareNotEqual(const A &a, const B &b) { return Compare<A,B>::notEqual(a,b); }

0 commit comments

Comments
 (0)