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::atomic_str_eq Struct Referencefinal

Custom equality functor for atomic_str_ptr and compatible types. More...

#include <jh/core/immutable_str.h>

Public Member Functions

template<typename U, typename V>
bool operator() (const U &lhs, const V &rhs) const noexcept

Detailed Description

Custom equality functor for atomic_str_ptr and compatible types.

Provides content-based comparison for immutable_str instances, enabling heterogeneous lookups in hash-based containers. Unlike the default std::shared_ptr equality operator, which compares raw pointer addresses, this functor compares the underlying string data safely and consistently.

  • Supports both atomic_str_ptr and const char* operands, constrained by immutable_str_compatible.
  • Allows transparent comparison in containers storing atomic_str_ptr keys — e.g., map.find("key") is valid and efficient.
  • At least one operand (lhs or rhs) must represent a valid immutable_str instance.
  • When JH_IMMUTABLE_STR_AUTO_TRIM is enabled, leading and trailing ASCII whitespace are ignored during comparison.
  • Comparison is symmetric and implementation-agnostic: either operand may be dereferenced first if future optimizations require it.
Template Parameters
UType of the left-hand side operand (atomic_str_ptr or const char*).
VType of the right-hand side operand (atomic_str_ptr or const char*).
Parameters
lhsLeft-hand side value to compare.
rhsRight-hand side value to compare.
Returns
true if the strings are equal (after trimming if enabled); false otherwise or if either side is nullptr.
Note
  • This functor is designed for containers whose key type is atomic_str_ptr, but supports lookup using const char* and string literals.
  • At least one operand must be an immutable_str to ensure pointer safety and avoid undefined behavior.
  • Whitespace trimming behavior is compile-time controlled via JH_IMMUTABLE_STR_AUTO_TRIM.
  • The nested is_transparent typedef enables heterogeneous comparison in unordered containers.

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