Skip to content

Instantly share code, notes, and snippets.

@serg06
Created May 24, 2020 00:12
Show Gist options
  • Save serg06/ac720db1885b90a8a01beb13e278b20d to your computer and use it in GitHub Desktop.
Save serg06/ac720db1885b90a8a01beb13e278b20d to your computer and use it in GitHub Desktop.
std::equal_to modified to dereference pointers N times before comparing
// 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