Skip to content

Commit

Permalink
tiny
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Aug 11, 2024
1 parent e4b2285 commit 3135eac
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions include/loki/details/utils/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,26 @@ concept HasHashMemberFunction = requires(T a)
/// @brief `Hash` implements hashing of types T.
/// If a type T provides a function hash() that returns a size_t then use it.
/// Otherwise, fallback to using std::hash instead.
/// If Deref is set to true, the type T must be dereferencable, and
/// in which case the object of type T is deferences before computing the hash value.
/// @tparam T
/// @tparam Deref
template<typename T, bool Deref>
struct Hash
{
size_t operator()(const T& element) const
{
if constexpr (Deref && IsDereferencable<T>)
if constexpr (Deref)
{
static_assert(IsDereferencable<T>);

if (!element)
{
throw std::logic_error("Hash<T, Deref>::operator(): Tried to illegally dereference an object.");
}
using DereferencedType = std::decay_t<decltype(*element)>;
return loki::Hash<DereferencedType, Deref>()(*element);
// The type T is a value type after deferencing, so we can set Deref = false.
return loki::Hash<DereferencedType, false>()(*element);
}
else if constexpr (HasHashMemberFunction<T>)
{
Expand Down

0 comments on commit 3135eac

Please sign in to comment.