9#include "../microfmt.hpp"
22template <
typename T,
typename =
void>
struct is_hashable : std::false_type {};
30struct is_hashable<T, std::void_t<decltype(std::hash<T>{}(std::declval<const T &>()))>> : std::true_type {};
50template <
typename T>
class RELOCO_POINTER
hash_view {
56 constexpr explicit hash_view(
const T &val RELOCO_LIFETIMEBOUND) noexcept : val_(val) {}
64 [[nodiscard]] std::size_t
compute_hash() const noexcept {
return std::hash<T>{}(*val_); }
68 value_ref<const T> val_;
81template <
typename T, std::enable_if_t<detail::is_hashable_v<T>,
int> = 0>
82[[nodiscard]]
constexpr auto as_hash(
const T &val RELOCO_LIFETIMEBOUND)
noexcept {
86template <
typename T, std::enable_if_t<
87 !std::is_lvalue_reference_v<T> && detail::is_hashable_v<std::remove_reference_t<T>>,
int> = 0>
88[[nodiscard]]
constexpr auto as_hash(T &&) noexcept = delete;
Definition microfmt.hpp:881
Non-owning view that defers a value's hash computation to formatting time.
Definition hash.hpp:50
constexpr hash_view(const T &val RELOCO_LIFETIMEBOUND) noexcept
Constructs a hash view referencing an existing value.
Definition hash.hpp:56
std::size_t compute_hash() const noexcept
Computes the hash of the referenced value.
Definition hash.hpp:64
constexpr hash_view(const T &&)=delete
constexpr bool is_hashable_v
Convenience variable template for is_hashable.
Definition hash.hpp:36
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
constexpr auto as_hash(const T &val RELOCO_LIFETIMEBOUND) noexcept
Wraps a value in an hash_view for hashed formatting.
Definition hash.hpp:82
SFINAE trait detecting types invocable through std::hash<T>.
Definition hash.hpp:22