Created
May 24, 2020 00:12
-
-
Save serg06/ac720db1885b90a8a01beb13e278b20d to your computer and use it in GitHub Desktop.
std::equal_to modified to dereference pointers N times before comparing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Similar to std::equal_to but dereferences pointers `derefs` times before comparing | |
template<class T, const int derefs> | |
struct deref_equal_to | |
{ | |
constexpr bool operator()(const T& lhs, const T& rhs) const | |
{ | |
static_assert(derefs >= 0); | |
if constexpr (derefs >= 1) | |
{ | |
static_assert(std::is_pointer_v<T>); | |
return deref_equal_to<std::remove_pointer_t<T>, derefs - 1>()(*lhs, *rhs); | |
} | |
else | |
{ | |
return std::equal_to<T>()(lhs, rhs); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment