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
hashable.h File Reference

Unified hashing concept suite with semantic extension and ADL support. More...

#include <concepts>
#include <functional>
#include <type_traits>
#include <utility>

Go to the source code of this file.

Classes

struct  jh::hash< T, std::enable_if_t< jh::concepts::has_std_hash< T > > >
 Case 1: std::hash<T> is valid. More...
struct  jh::hash< T, std::enable_if_t<!jh::concepts::has_std_hash< T > &&jh::concepts::has_adl_hash< T > > >
 Case 2: ADL-discovered hash(T). More...
struct  jh::hash< T, std::enable_if_t<!jh::concepts::has_std_hash< T > &&!jh::concepts::has_adl_hash< T > &&jh::concepts::has_mbr_hash< T > > >
 Case 3: Member hash(). More...

Namespaces

namespace  jh::concepts
 Behavioral concept namespace of the JH Toolkit.

Concepts

concept  jh::concepts::has_std_hash
 Checks whether std::hash<T> is valid and callable.
concept  jh::concepts::has_adl_hash
 Checks whether a free (ADL-discoverable) hash() function exists.
concept  jh::concepts::has_mbr_hash
 Checks whether a type defines a hash() member function.
concept  jh::concepts::extended_hashable
 Concept for types that can be hashed through any supported mechanism.

Detailed Description

Unified hashing concept suite with semantic extension and ADL support.

Author
JeongHan-Bae <mastropseudo@gmail.com>

This header defines the duck-typed hashability model used by the JH framework. It generalizes hashing semantics beyond std::hash<T> by allowing user-defined and semantically meaningful hash strategies.

Why Allow Custom Hashing?

While std::hash<T> provides a universal entry point for associative containers, it cannot describe semantic-specific hash behaviors such as:

  • Lazy evaluation — deferred hash computation with caching (e.g. jh::immutable_str).
  • Algorithm selection — e.g. jh::pod::string_view uses c_hash::fnv1a64 by default, but may switch algorithms via an enum parameter.
  • Semantic integrity — certain domain-specific hashes carry meaning beyond raw bytes (e.g. type-level discriminators, persistent keys, etc.).

Therefore, the JH framework permits three resolution layers:

  1. Standard hashstd::hash<T>{} (highest precedence)
  2. ADL-discovered free hash() — found via argument-dependent lookup
  3. Member function hash()t.hash() if provided

This priority chain ensures full interoperability with the STL, while supporting domain-specific customization and lazy semantics without breaking standard containers.

Version
1.3.x
Date
2025