#ifndef __JLANG__JCOMPARISONAVAILABLE__ #define __JLANG__JCOMPARISONAVAILABLE__ #include "JLang/JNullType.hh" #include "JLang/JAnyType.hh" #include "JLang/JVoid.hh" #include "JLang/JTest.hh" /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Local namespace for fallback implementations for comparison operators. */ namespace JLOCAL { /** * Fallback implementations for comparison operators. */ inline JNullType operator==(JAnyType, JAnyType) { return JNullType(); } inline JNullType operator!=(JAnyType, JAnyType) { return JNullType(); } inline JNullType operator< (JAnyType, JAnyType) { return JNullType(); } inline JNullType operator> (JAnyType, JAnyType) { return JNullType(); } inline JNullType operator<=(JAnyType, JAnyType) { return JNullType(); } inline JNullType operator>=(JAnyType, JAnyType) { return JNullType(); } /** * Test availability of comparison operators of non-composite data types. */ template class JComparisonAvailable : public JTest { using JTest::test; static JTrue test(const bool&); static T& getReference(); public: static const bool has_eq = JTEST(test(getReference() == getReference())); //!< true if operator== available; else false static const bool has_ne = JTEST(test(getReference() != getReference())); //!< true if operator!= available; else false static const bool has_lt = JTEST(test(getReference() < getReference())); //!< true if operator< available; else false static const bool has_gt = JTEST(test(getReference() > getReference())); //!< true if operator> available; else false static const bool has_le = JTEST(test(getReference() <= getReference())); //!< true if operator<= available; else false static const bool has_ge = JTEST(test(getReference() >= getReference())); //!< true if operator>= available; else false }; /** * Test availability of comparison operators of data types which have a type definitions for first_type and second_type. * This applies to STL containers such as std::map. * Note that STL provides for the comparison of the container based on comparisons of its elements. */ template class JComparisonAvailable::type> { typedef typename T::first_type first_type; typedef typename T::second_type second_type; public: static const bool has_eq = JComparisonAvailable::has_eq && JComparisonAvailable::has_eq; static const bool has_ne = JComparisonAvailable::has_ne && JComparisonAvailable::has_ne; static const bool has_lt = JComparisonAvailable::has_lt && JComparisonAvailable::has_lt; static const bool has_gt = JComparisonAvailable::has_gt && JComparisonAvailable::has_gt; static const bool has_le = JComparisonAvailable::has_le && JComparisonAvailable::has_le; static const bool has_ge = JComparisonAvailable::has_ge && JComparisonAvailable::has_ge; }; /** * Test availability of comparison operators of data types which have a type definition for value_type. * This applies to STL containers such as std::vector and std::set. * Note that STL provides for the comparison of the container based on comparisons of its elements. */ template class JComparisonAvailable::type> : public JComparisonAvailable {}; /** * Template base class for data structures without equality capability. * This class implements the operators == != . */ template class JNoequals { private: /** * Equal operator. * * \param first first object * \param second second object * \return true if two objects are equal; else false */ friend JNullType operator==(const T& first, const T& second) { return JNullType(); } /** * Not equal operator. * * \param first first object * \param second second object * \return true if two objects are not equal; else false */ friend JNullType operator!=(const T& first, const T& second) { return JNullType(); } }; } using JLOCAL::JComparisonAvailable; using JLOCAL::JNoequals; } #endif