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 MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (UInt32 h)
 
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (UInt64 h)
 
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Bool i)
 
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Char i)
 
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (UChar i)
 
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Int16 i)
 
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (UInt16 i)
 
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Int32 h)
 
static HashInt GetHashCode (Utf16Char i)
 
static HashInt GetHashCode (Utf32Char i)
 
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Int64 h)
 
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Float32 h)
 
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (Float64 h)
 
template<typename T >
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (const T *key)
 
template<typename T >
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (T *key)
 
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (std::nullptr_t)
 
template<typename E >
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (const maxon::details::EnumWrapper< E > &key)
 
template<typename K >
static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode (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 const MAXON_ATTRIBUTE_FORCE_INLINE 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 HashInt GetCombinedHashCode (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 MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCodeHelper (const K &key, OverloadRank0)
 
template<typename K >
static MAXON_ATTRIBUTE_FORCE_INLINE auto GetHashCodeHelper (const K &key, OverloadRank1) -> decltype(key.GetHashCode())
 
template<typename K >
static MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< STD_IS_REPLACEMENT(enum, K), UInt >::type GetHashCodeHelper (const K &key, OverloadRank2)
 

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 MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( UInt32  h)
static

◆ GetHashCode() [2/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( UInt64  h)
static

◆ GetHashCode() [3/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Bool  i)
static

◆ GetHashCode() [4/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Char  i)
static

◆ GetHashCode() [5/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( UChar  i)
static

◆ GetHashCode() [6/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Int16  i)
static

◆ GetHashCode() [7/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( UInt16  i)
static

◆ GetHashCode() [8/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Int32  h)
static

◆ GetHashCode() [9/18]

static HashInt GetHashCode ( Utf16Char  i)
static

◆ GetHashCode() [10/18]

static HashInt GetHashCode ( Utf32Char  i)
static

◆ GetHashCode() [11/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Int64  h)
static

◆ GetHashCode() [12/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Float32  h)
static

◆ GetHashCode() [13/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( Float64  h)
static

◆ GetHashCode() [14/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( const T *  key)
static

◆ GetHashCode() [15/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( T *  key)
static

◆ GetHashCode() [16/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( std::nullptr_t  )
static

◆ GetHashCode() [17/18]

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

◆ GetHashCode() [18/18]

static MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCode ( 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 const MAXON_ATTRIBUTE_FORCE_INLINE 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 HashInt GetCombinedHashCode ( 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 MAXON_ATTRIBUTE_FORCE_INLINE HashInt GetHashCodeHelper ( const K &  key,
OverloadRank0   
)
staticprivate

◆ GetHashCodeHelper() [2/3]

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

◆ GetHashCodeHelper() [3/3]

static MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if<STD_IS_REPLACEMENT(enum, K), UInt>::type GetHashCodeHelper ( const K &  key,
OverloadRank2   
)
staticprivate

Friends And Related Function Documentation

◆ DefaultDataTypeFunctionsCapabilityFlags