hash/std: add a trivial adapter for std::hash
This commit is contained in:
parent
c011b2177c
commit
ef309fd4de
@ -425,6 +425,8 @@ list (
|
|||||||
hash/murmur/murmur3.hpp
|
hash/murmur/murmur3.hpp
|
||||||
hash/siphash.cpp
|
hash/siphash.cpp
|
||||||
hash/siphash.hpp
|
hash/siphash.hpp
|
||||||
|
hash/std.cpp
|
||||||
|
hash/std.hpp
|
||||||
hash/table.cpp
|
hash/table.cpp
|
||||||
hash/table.hpp
|
hash/table.hpp
|
||||||
hash/tuple.cpp
|
hash/tuple.cpp
|
||||||
|
1
hash/std.cpp
Normal file
1
hash/std.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "./std.hpp"
|
21
hash/std.hpp
Normal file
21
hash/std.hpp
Normal 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));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user