hash/std: add a trivial adapter for std::hash

This commit is contained in:
Danny Robson 2023-07-24 13:09:06 +10:00
parent c011b2177c
commit ef309fd4de
3 changed files with 24 additions and 0 deletions

View File

@ -425,6 +425,8 @@ list (
hash/murmur/murmur3.hpp
hash/siphash.cpp
hash/siphash.hpp
hash/std.cpp
hash/std.hpp
hash/table.cpp
hash/table.hpp
hash/tuple.cpp

1
hash/std.cpp Normal file
View File

@ -0,0 +1 @@
#include "./std.hpp"

21
hash/std.hpp Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#include <utility>
#include <type_traits>
#include <functional>
namespace cruft::hash {
// A trivial adapter around the `std::hash` that avoids the need to
// specify the type up front.
//
// Useful as a component in more complex hash objects (eg, hash::tuple)
struct std {
template <typename ValueT>
auto operator () (ValueT &&val)
{
using inner_t = ::std::remove_cvref_t<ValueT>;
return ::std::hash<inner_t> {} (::std::forward<ValueT> (val));
}
};
}