CompareTemplate< ALLOW_UNDEFINED, EQ, OPERATOR_RANK > Class Template Reference

#include <compare.h>

Detailed Description

template<Bool ALLOW_UNDEFINED, EQUALITY EQ = EQUALITY::SHALLOW, typename OPERATOR_RANK = OverloadRank5>
class maxon::CompareTemplate< ALLOW_UNDEFINED, EQ, OPERATOR_RANK >

This class implements default compare and hash functions. They are used at various places such as DataType or HashMap. The class defines IsEqual and GetHashCode for the following cases:

  • arithmetic and enumeration values
  • pointers (where different pointers are assumed to be different keys, so only the address is considered, not the content)
  • strong non-copy-on-write references (using their pointer)
  • objects whose type has a GetHashCode member function and which can be compared with == The class defines Compare for the following cases:
  • arithmetic values

For any other case you can specialize the template functions of DefaultCompare, or you have to define your own comparison and hash function class, see CStringCompare for the case of C-strings.

Note that hashes are not meant to be stored in files as they are only valid during runtime. The datatype for hashes is UInt which is variable in width.

Static Public Member Functions

template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE COMPARERESULT Compare (const T1 &a, const T2 &b)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (UInt32 h)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (UInt64 h)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Bool i)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Char i)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (UChar i)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Int16 i)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (UInt16 i)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Int32 h)
 
static constexpr HashInt GetHashCode (Utf16Char i)
 
static constexpr HashInt GetHashCode (Utf32Char i)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Int64 h)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Float32 h)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Float64 h)
 
template<typename T >
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (const T *key)
 
template<typename T >
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (T *key)
 
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (std::nullptr_t)
 
template<typename E >
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (const maxon::details::EnumWrapper< E > &key)
 
template<typename K >
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (const K &key)
 
template<typename K >
static MAXON_ATTRIBUTE_FORCE_INLINE UniqueHash GetUniqueHashCode (const K &key)
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE Bool IsEqual (const T1 &a, const T2 &b)
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE Bool LessThan (const T1 &a, const T2 &b)
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE Bool LessThanOrEqual (const T1 &a, const T2 &b)
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE const COMPARERESULTCompareHelper (const T1 &a, const T2 &b, OverloadRank0)
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE auto CompareHelper (const T1 &a, const T2 &b, OverloadRank1) -> decltype((a< b) ? COMPARERESULT::LESS :COMPARERESULT::EQUAL)
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE auto CompareHelper (const T1 &a, const T2 &b, OverloadRank2) -> decltype(a.Compare(b))
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE SFINAEHelper< COMPARERESULT, typename T1::PartiallyOrdered >::type CompareHelper (const T1 &a, const T2 &b, OverloadRank3)
 
template<typename... T>
static constexpr HashInt GetCombinedHashCode (const T &... values)
 
template<typename... T>
static UniqueHash GetCombinedUniqueHash (const T &... values)
 

Static Private Member Functions

template<typename K1 , typename K2 >
static MAXON_ATTRIBUTE_FORCE_INLINE Bool IsEqualHelper (const K1 &a, const K2 &b, OverloadRank0)
 
static Bool DecltypeIsEqualHelper (COMPARERESULT)
 
template<typename K1 , typename K2 >
static MAXON_ATTRIBUTE_FORCE_INLINE auto IsEqualHelper (const K1 &a, const K2 &b, OverloadRank2) -> decltype(DecltypeIsEqualHelper(a.Compare(b)))
 
template<typename K1 , typename K2 >
static MAXON_ATTRIBUTE_FORCE_INLINE auto IsEqualHelper (const K1 &a, const K2 &b, OverloadRank3) -> decltype(a.IsEqual(b))
 
template<typename K1 , typename K2 >
static MAXON_ATTRIBUTE_FORCE_INLINE auto IsEqualHelper (const K1 &a, const K2 &b, OverloadRank4) -> decltype(a.IsEqual(b, EQ))
 
template<typename K1 , typename K2 >
static MAXON_ATTRIBUTE_FORCE_INLINE auto IsEqualHelper (const K1 &a, const K2 &b, OPERATOR_RANK) -> decltype(a==b)
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE Bool LessThanOrEqualHelper (const T1 &a, const T2 &b, OverloadRank0)
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE auto LessThanOrEqualHelper (const T1 &a, const T2 &b, OverloadRank1) -> decltype(a.LessThan(b))
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE auto LessThanOrEqualHelper (const T1 &a, const T2 &b, OverloadRank2) -> decltype(a.LessThanOrEqual(b))
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE auto LessThanOrEqualHelper (const T1 &a, const T2 &b, OverloadRank3) -> decltype(a<=b)
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE Bool LessThanHelper (const T1 &a, const T2 &b, OverloadRank0)
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE auto LessThanHelper (const T1 &a, const T2 &b, OverloadRank1) -> decltype(a.LessThan(b))
 
template<typename T1 , typename T2 >
static MAXON_ATTRIBUTE_FORCE_INLINE auto LessThanHelper (const T1 &a, const T2 &b, OverloadRank2) -> decltype(a< b)
 
template<typename K >
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCodeHelper (const K &key, OverloadRank0)
 
template<typename K >
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE auto GetHashCodeHelper (const K &key, OverloadRank1) -> decltype(key.GetHashCode())
 
template<typename K >
static constexpr MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< STD_IS_REPLACEMENT(enum, K), HashInt >::type GetHashCodeHelper (const K &key, OverloadRank2)
 
template<typename K >
static MAXON_ATTRIBUTE_FORCE_INLINE UniqueHash GetUniqueHashCodeHelper (const K &key, OverloadRank0)
 
template<typename K >
static MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< IsTriviallyHashable< K >::value, UniqueHash >::type GetUniqueHashCodeHelper (const K &key, OverloadRank1)
 
template<typename K >
static MAXON_ATTRIBUTE_FORCE_INLINE auto GetUniqueHashCodeHelper (const K &key, OverloadRank2) -> decltype(key.GetUniqueHashCode())
 

Friends

template<typename T >
struct DefaultDataTypeFunctionsCapabilityFlags
 

Member Function Documentation

◆ Compare()

static MAXON_ATTRIBUTE_FORCE_INLINE COMPARERESULT Compare ( const T1 &  a,
const T2 &  b 
)
static

◆ GetHashCode() [1/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( UInt32  h)
staticconstexpr

◆ GetHashCode() [2/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( UInt64  h)
staticconstexpr

◆ GetHashCode() [3/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Bool  i)
staticconstexpr

◆ GetHashCode() [4/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Char  i)
staticconstexpr

◆ GetHashCode() [5/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( UChar  i)
staticconstexpr

◆ GetHashCode() [6/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Int16  i)
staticconstexpr

◆ GetHashCode() [7/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( UInt16  i)
staticconstexpr

◆ GetHashCode() [8/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Int32  h)
staticconstexpr

◆ GetHashCode() [9/18]

static constexpr HashInt GetHashCode ( Utf16Char  i)
staticconstexpr

◆ GetHashCode() [10/18]

static constexpr HashInt GetHashCode ( Utf32Char  i)
staticconstexpr

◆ GetHashCode() [11/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Int64  h)
staticconstexpr

◆ GetHashCode() [12/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Float32  h)
staticconstexpr

◆ GetHashCode() [13/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Float64  h)
staticconstexpr

◆ GetHashCode() [14/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( const T *  key)
staticconstexpr

◆ GetHashCode() [15/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( T *  key)
staticconstexpr

◆ GetHashCode() [16/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( std::nullptr_t  )
staticconstexpr

◆ GetHashCode() [17/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( const maxon::details::EnumWrapper< E > &  key)
staticconstexpr

◆ GetHashCode() [18/18]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( const K &  key)
staticconstexpr

◆ GetUniqueHashCode()

static MAXON_ATTRIBUTE_FORCE_INLINE UniqueHash GetUniqueHashCode ( const K &  key)
static

◆ IsEqual()

static MAXON_ATTRIBUTE_FORCE_INLINE Bool IsEqual ( const T1 &  a,
const T2 &  b 
)
static

◆ LessThan()

static MAXON_ATTRIBUTE_FORCE_INLINE Bool LessThan ( const T1 &  a,
const T2 &  b 
)
static

◆ LessThanOrEqual()

static MAXON_ATTRIBUTE_FORCE_INLINE Bool LessThanOrEqual ( const T1 &  a,
const T2 &  b 
)
static

◆ CompareHelper() [1/4]

static MAXON_ATTRIBUTE_FORCE_INLINE const COMPARERESULT& CompareHelper ( const T1 &  a,
const T2 &  b,
OverloadRank0   
)
static

◆ CompareHelper() [2/4]

static MAXON_ATTRIBUTE_FORCE_INLINE auto CompareHelper ( const T1 &  a,
const T2 &  b,
OverloadRank1   
) -> decltype((a < b) ? COMPARERESULT::LESS : COMPARERESULT::EQUAL)
static

◆ CompareHelper() [3/4]

static MAXON_ATTRIBUTE_FORCE_INLINE auto CompareHelper ( const T1 &  a,
const T2 &  b,
OverloadRank2   
) -> decltype(a.Compare(b))
static

◆ CompareHelper() [4/4]

static MAXON_ATTRIBUTE_FORCE_INLINE SFINAEHelper<COMPARERESULT, typename T1::PartiallyOrdered>::type CompareHelper ( const T1 &  a,
const T2 &  b,
OverloadRank3   
)
static

◆ GetCombinedHashCode()

static constexpr HashInt GetCombinedHashCode ( const T &...  values)
staticconstexpr

◆ GetCombinedUniqueHash()

static UniqueHash GetCombinedUniqueHash ( const T &...  values)
static

◆ IsEqualHelper() [1/5]

static MAXON_ATTRIBUTE_FORCE_INLINE Bool IsEqualHelper ( const K1 &  a,
const K2 &  b,
OverloadRank0   
)
staticprivate

◆ DecltypeIsEqualHelper()

static Bool DecltypeIsEqualHelper ( COMPARERESULT  )
staticprivate

◆ IsEqualHelper() [2/5]

static MAXON_ATTRIBUTE_FORCE_INLINE auto IsEqualHelper ( const K1 &  a,
const K2 &  b,
OverloadRank2   
) -> decltype(DecltypeIsEqualHelper(a.Compare(b)))
staticprivate

◆ IsEqualHelper() [3/5]

static MAXON_ATTRIBUTE_FORCE_INLINE auto IsEqualHelper ( const K1 &  a,
const K2 &  b,
OverloadRank3   
) -> decltype(a.IsEqual(b))
staticprivate

◆ IsEqualHelper() [4/5]

static MAXON_ATTRIBUTE_FORCE_INLINE auto IsEqualHelper ( const K1 &  a,
const K2 &  b,
OverloadRank4   
) -> decltype(a.IsEqual(b, EQ))
staticprivate

◆ IsEqualHelper() [5/5]

static MAXON_ATTRIBUTE_FORCE_INLINE auto IsEqualHelper ( const K1 &  a,
const K2 &  b,
OPERATOR_RANK   
) -> decltype(a == b)
staticprivate

◆ LessThanOrEqualHelper() [1/4]

static MAXON_ATTRIBUTE_FORCE_INLINE Bool LessThanOrEqualHelper ( const T1 &  a,
const T2 &  b,
OverloadRank0   
)
staticprivate

◆ LessThanOrEqualHelper() [2/4]

static MAXON_ATTRIBUTE_FORCE_INLINE auto LessThanOrEqualHelper ( const T1 &  a,
const T2 &  b,
OverloadRank1   
) -> decltype(a.LessThan(b))
staticprivate

◆ LessThanOrEqualHelper() [3/4]

static MAXON_ATTRIBUTE_FORCE_INLINE auto LessThanOrEqualHelper ( const T1 &  a,
const T2 &  b,
OverloadRank2   
) -> decltype(a.LessThanOrEqual(b))
staticprivate

◆ LessThanOrEqualHelper() [4/4]

static MAXON_ATTRIBUTE_FORCE_INLINE auto LessThanOrEqualHelper ( const T1 &  a,
const T2 &  b,
OverloadRank3   
) -> decltype(a <= b)
staticprivate

◆ LessThanHelper() [1/3]

static MAXON_ATTRIBUTE_FORCE_INLINE Bool LessThanHelper ( const T1 &  a,
const T2 &  b,
OverloadRank0   
)
staticprivate

◆ LessThanHelper() [2/3]

static MAXON_ATTRIBUTE_FORCE_INLINE auto LessThanHelper ( const T1 &  a,
const T2 &  b,
OverloadRank1   
) -> decltype(a.LessThan(b))
staticprivate

◆ LessThanHelper() [3/3]

static MAXON_ATTRIBUTE_FORCE_INLINE auto LessThanHelper ( const T1 &  a,
const T2 &  b,
OverloadRank2   
) -> decltype(a < b)
staticprivate

◆ GetHashCodeHelper() [1/3]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCodeHelper ( const K &  key,
OverloadRank0   
)
staticconstexprprivate

◆ GetHashCodeHelper() [2/3]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE auto GetHashCodeHelper ( const K &  key,
OverloadRank1   
) -> decltype(key.GetHashCode())
staticconstexprprivate

◆ GetHashCodeHelper() [3/3]

static constexpr MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if<STD_IS_REPLACEMENT(enum, K), HashInt>::type GetHashCodeHelper ( const K &  key,
OverloadRank2   
)
staticconstexprprivate

◆ GetUniqueHashCodeHelper() [1/3]

static MAXON_ATTRIBUTE_FORCE_INLINE UniqueHash GetUniqueHashCodeHelper ( const K &  key,
OverloadRank0   
)
staticprivate

◆ GetUniqueHashCodeHelper() [2/3]

static MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if<IsTriviallyHashable<K>::value, UniqueHash>::type GetUniqueHashCodeHelper ( const K &  key,
OverloadRank1   
)
staticprivate

◆ GetUniqueHashCodeHelper() [3/3]

static MAXON_ATTRIBUTE_FORCE_INLINE auto GetUniqueHashCodeHelper ( const K &  key,
OverloadRank2   
) -> decltype(key.GetUniqueHashCode())
staticprivate

Friends And Related Function Documentation

◆ DefaultDataTypeFunctionsCapabilityFlags