Reference Guide: Comparator Functions

Comparators are functions able to compare two values of same type and tell which one is smaller/equal/greater. They are a requirement of Hash Table and Red Black Tree data structures and thus must be provided for all classes that use any of latter. API makes it extremely easy by asking you to just specialize default comparator for each type you want to support.

For testing purposes, API already ships with two specializations: one for long data type, the other for char* data type. Let's say, for example, you want it to support double data type as well! In that case you need to provide a specialization such as:

template<> inline int comparator(const double& left, const double& right) { if(left < right) { return -1; } else if(left == right) { return 0; } else { return 1; } }

comparator

Function implementing a comparator that by default does nothing, to be extended by developers through template specialization for each data type they want to support

Signature

template <typename T> inline int comparator(const T& left, const T& right)

comparator<long>

Function specializing default comparator for LONG data type, implemented by API already

Signature

template <> inline int comparator(const long& left, const long& right)

comparator<char*>

Function specializing default comparator for CHAR* data type, implemented by API already

Signature

template <> inline int comparator(char* const& left, char* const& right)
Share