Functions for equality comparisons
Overview
These are helper functions that, at compiler time, detect if the fitness_t
is a floating point type, and applies the absolute diference. More…
// global functions template <class T> constexpr bool BRKGA::close_enough( T a, T b ); template < size_t I = 0, typename T, typename... Ts > constexpr bool BRKGA::close_enough( std::tuple<T, Ts...> a, std::tuple<T, Ts...> b );
Detailed Documentation
These are helper functions that, at compiler time, detect if the fitness_t
is a floating point type, and applies the absolute diference. Otherwise, the compiler generates the equality comparison.
Global Functions
template <class T> constexpr bool BRKGA::close_enough( T a, T b )
Compares two values to equality.
If these values are real numbers, we compare their absolute difference with EQUALITY_THRESHOLD
, i.e., \(|a - b| < EQUALITY\_THRESHOLD\). In other cases (except tuples, which have a specialization), we use the operator==
directly. Therefore, fitness_t
must define operator==
.
Parameters:
a |
First item to be compared. |
b |
Second item to be compared. |
Returns:
true if a and b are equal.
template < size_t I = 0, typename T, typename... Ts > constexpr bool BRKGA::close_enough( std::tuple<T, Ts...> a, std::tuple<T, Ts...> b )
Compares two tuples to equality.
This specialization iterates, recursively, of each tuples’ members and compares them. Note that this is done in compilation time, with no impact at running time.
Parameters:
a |
First tuple to be compared. |
b |
Second tuple to be compared. |
Returns:
true if a and b are equal.