Use if constexpr (C++17 feature)

This commit is contained in:
Mat Sutcliffe
2021-04-17 21:57:20 +01:00
parent 5d67cd9f68
commit d7a461ff7a
11 changed files with 103 additions and 189 deletions

View File

@@ -151,12 +151,12 @@ namespace BlackMisc
protected:
//! Efficiently compare addresses of two objects. Return false if types are not compatible.
//! @{
template <typename T, typename U, std::enable_if_t<TIsEqualityComparable<const T *, const U *>::value, int> = 0>
static bool equalPointers(const T *a, const U *b) { return a == b; }
template <typename T, typename U, std::enable_if_t<! TIsEqualityComparable<const T *, const U *>::value, int> = 0>
static bool equalPointers(const T *, const U *) { return false; }
//! @}
template <typename T, typename U>
static bool equalPointers(const T *a, const U *b)
{
if constexpr (TIsEqualityComparable<const T *, const U *>::value) { return a == b; }
else { return false; }
}
private:
Derived &derived() { return static_cast<Derived &>(*this); }