JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers โ€” header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
jh::weak_ptr_hash< T > Struct Template Referencefinal

Content-based hash functor for std::weak_ptr<T>. More...

#include <jh/concurrent/observe_pool.h>

Public Member Functions

std::size_t operator() (const std::weak_ptr< T > &ptr) const noexcept

Detailed Description

template<typename T>
requires jh::concepts::extended_hashable<T>
struct jh::weak_ptr_hash< T >

Content-based hash functor for std::weak_ptr<T>.

Behavior

  • If the pointer is expired, returns 0.
  • If valid, locks and applies the unified jh::hash<T> functor to the underlying object.
  • Ensures consistent results during concurrent insertion into a jh::observe_pool by performing a single well-defined hash access per locked instance.

Purpose

Enables jh::observe_pool and jh::conc::pointer_pool to hash weakly referenced shared objects by logical content, without altering ownership or extending object lifetimes.

Version Note (since 1.3.5)

Starting with 1.3.5, weak_ptr_hash<T> supports automatic hash deduction through jh::hash<T>, which transparently resolves hashing via the following precedence chain:


std::hash<T>{ }(v)
  >  hash(v)
  >  v.hash()

This allows any type declaring a valid hash mechanism โ€” standard, ADL-based, or member-based โ€” to participate in pooling without the need for custom specialization.

Template Parameters
TThe managed type, which must satisfy jh::concepts::extended_hashable.
See also
jh::concepts::extended_hashable
jh::hash

The documentation for this struct was generated from the following file: