Jpp
JComparisonAvailable.hh
Go to the documentation of this file.
1 
2 #ifndef __JLANG__JCOMPARISONAVAILABLE__
3 #define __JLANG__JCOMPARISONAVAILABLE__
4 
5 #include "JLang/JNullType.hh"
6 #include "JLang/JAnyType.hh"
7 #include "JLang/JVoid.hh"
8 #include "JLang/JTest.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JLANG {}
16 namespace JPP { using namespace JLANG; }
17 
18 namespace JLANG {
19 
20  namespace JLOCAL {
21 
22  /**
23  * Fallback implementations for comparison operators.
24  */
31 
32 
33  /**
34  * Test availability of comparison operators of non-composite data types.
35  */
36  template<class T, class JType_t = void>
38  public JTest
39  {
40  using JTest::test;
41 
42  static JTrue test(const bool&);
43 
44  static T& getReference();
45 
46  public:
47  static const bool has_eq = JTEST(test(getReference() == getReference())); //!< true if operator== available; else false
48  static const bool has_ne = JTEST(test(getReference() != getReference())); //!< true if operator!= available; else false
49  static const bool has_lt = JTEST(test(getReference() < getReference())); //!< true if operator< available; else false
50  static const bool has_gt = JTEST(test(getReference() > getReference())); //!< true if operator> available; else false
51  static const bool has_le = JTEST(test(getReference() <= getReference())); //!< true if operator<= available; else false
52  static const bool has_ge = JTEST(test(getReference() >= getReference())); //!< true if operator>= available; else false
53  };
54 
55 
56  /**
57  * Test availability of comparison operators of data types which have a type definitions for first_type and second_type.
58  * This applies to STL containers such as std::map.
59  * Note that STL provides for the comparison of the container based on comparisons of its elements.
60  */
61  template<class T>
62  class JComparisonAvailable<T, typename JVoid<typename T::second_type>::type>
63  {
64  typedef typename T::first_type first_type;
65  typedef typename T::second_type second_type;
66 
67  public:
74  };
75 
76 
77  /**
78  * Test availability of comparison operators of data types which have a type definition for value_type.
79  * This applies to STL containers such as std::vector and std::set.
80  * Note that STL provides for the comparison of the container based on comparisons of its elements.
81  */
82  template<class T>
83  class JComparisonAvailable<T, typename JVoid<typename T::value_type>::type> :
84  public JComparisonAvailable<typename T::value_type>
85  {};
86 
87 
88  /**
89  * Template base class for data structures without equality capability.
90  * This class implements the operators <tt> == != </tt>.
91  */
92  template<class T>
93  class JNoequals {
94  private:
95  /**
96  * Equal operator.
97  *
98  * \param first first object
99  * \param second second object
100  * \return true if two objects are equal; else false
101  */
102  friend JNullType operator==(const T& first, const T& second)
103  {
104  return JNullType();
105  }
106 
107 
108  /**
109  * Not equal operator.
110  *
111  * \param first first object
112  * \param second second object
113  * \return true if two objects are not equal; else false
114  */
115  friend JNullType operator!=(const T& first, const T& second)
116  {
117  return JNullType();
118  }
119  };
120  }
121 
123  using JLOCAL::JNoequals;
124 }
125 
126 #endif
JLANG::JLOCAL::JComparisonAvailable::has_le
static const bool has_le
true if operator<= available; else false
Definition: JComparisonAvailable.hh:51
JLANG::JLOCAL::operator<
JNullType operator<(JAnyType, JAnyType)
Definition: JComparisonAvailable.hh:27
JLANG::JLOCAL::JComparisonAvailable
Test availability of comparison operators of non-composite data types.
Definition: JComparisonAvailable.hh:37
JLANG::JLOCAL::JComparisonAvailable::getReference
static T & getReference()
JLANG::JTest::JTrue
definition of true
Definition: JTest.hh:24
JLANG::JLOCAL::JComparisonAvailable::has_ge
static const bool has_ge
true if operator>= available; else false
Definition: JComparisonAvailable.hh:52
JLANG::JLOCAL::JComparisonAvailable::has_ne
static const bool has_ne
true if operator!= available; else false
Definition: JComparisonAvailable.hh:48
JLANG::JLOCAL::JComparisonAvailable< T, typename JVoid< typename T::second_type >::type >::first_type
T::first_type first_type
Definition: JComparisonAvailable.hh:64
JLANG::JLOCAL::operator>=
JNullType operator>=(JAnyType, JAnyType)
Definition: JComparisonAvailable.hh:30
JLANG::JNullType
Auxiliary class for no type definition.
Definition: JNullType.hh:19
JLANG::JTest::test
static JFalse test(...)
default false
JLANG::JLOCAL::JNoequals
Template base class for data structures without equality capability.
Definition: JComparisonAvailable.hh:93
JVoid.hh
JLANG::JLOCAL::JNoequals::operator!=
friend JNullType operator!=(const T &first, const T &second)
Not equal operator.
Definition: JComparisonAvailable.hh:115
JLANG::JTest
Auxiliary base class for compile time evaluation of test.
Definition: JTest.hh:21
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JTEST
#define JTEST(__A__)
Test macro.
Definition: JTest.hh:45
JAnyType.hh
JLANG::JLOCAL::JComparisonAvailable::has_lt
static const bool has_lt
true if operator< available; else false
Definition: JComparisonAvailable.hh:49
JLANG::JLOCAL::operator!=
JNullType operator!=(JAnyType, JAnyType)
Definition: JComparisonAvailable.hh:26
JLANG::JLOCAL::operator<=
JNullType operator<=(JAnyType, JAnyType)
Definition: JComparisonAvailable.hh:29
JLANG::JLOCAL::JComparisonAvailable< T, typename JVoid< typename T::second_type >::type >::second_type
T::second_type second_type
Definition: JComparisonAvailable.hh:65
JLANG::JLOCAL::operator==
JNullType operator==(JAnyType, JAnyType)
Fallback implementations for comparison operators.
Definition: JComparisonAvailable.hh:25
JLANG::JLOCAL::JNoequals::operator==
friend JNullType operator==(const T &first, const T &second)
Equal operator.
Definition: JComparisonAvailable.hh:102
JLANG::JVoid
Auxiliary class for void type definition.
Definition: JVoid.hh:20
JNullType.hh
JLANG
Auxiliary classes and methods for language specific functionality.
Definition: JAbstractClass.hh:10
JLANG::JLOCAL::JComparisonAvailable::test
static JTrue test(const bool &)
JLANG::JLOCAL::JComparisonAvailable::has_gt
static const bool has_gt
true if operator> available; else false
Definition: JComparisonAvailable.hh:50
JLANG::JLOCAL::operator>
JNullType operator>(JAnyType, JAnyType)
Definition: JComparisonAvailable.hh:28
JLANG::JAnyType
Auxiliary class for any type definition.
Definition: JAnyType.hh:19
JTest.hh
JLANG::JLOCAL::JComparisonAvailable::has_eq
static const bool has_eq
true if operator== available; else false
Definition: JComparisonAvailable.hh:47