Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JComparisonToolkit.hh
Go to the documentation of this file.
1#ifndef __JEEP__JCOMPARISONTOOLKIT__
2#define __JEEP__JCOMPARISONTOOLKIT__
3
4#include <string.h>
5#include <type_traits>
6
8
9
10/**
11 * \author mdejong
12 */
13
14namespace JEEP {}
15namespace JPP { using namespace JEEP; }
16
17namespace JEEP {
18
20
21
22
23 /**
24 * Comparison of comparable objects.
25 *
26 * \param first first object
27 * \param second second object
28 * \return true if objects are equal; else false
29 */
30 template<class T>
31 inline bool compareObjects(const T& first,
32 const T& second,
33 std::true_type)
34 {
35 return first == second;
36 }
37
38
39 /**
40 * Comparison of uncomparable objects.
41 *
42 * \param first first object
43 * \param second second object
44 * \return false
45 */
46 template<class T>
47 inline bool compareObjects(const T& first,
48 const T& second,
49 std::false_type)
50 {
51 return false;
52 }
53
54
55 /**
56 * Comparison of objects.
57 *
58 * \param first first object
59 * \param second second object
60 * \return true if objects are comparable and equal; else false
61 */
62 template<class T>
63 inline bool compareObjects(const T& first,
64 const T& second)
65 {
66 return compareObjects(first, second, std::bool_constant<JComparisonAvailable<T>::has_eq>());
67 }
68
69
70 /**
71 * Comparison of comparable objects.
72 *
73 * \param first first object
74 * \param second second object
75 * \return true if objects are equal; else false
76 */
77 template<int N>
78 inline bool compareObjects(const char (&first) [N],
79 const char (&second)[N])
80 {
81 return strcmp(first, second) == 0;
82 }
83
84}
85
86#endif
Template definition of test availability of comparison operators.
General puprpose classes and methods.
bool compareObjects(const T &first, const T &second, std::true_type)
Comparison of comparable objects.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).