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 Namespace Reference

Namespaces

namespace  async
 Aggregated entry point for coroutine-based asynchronous facilities.
namespace  concepts
 Behavioral concept namespace of the JH Toolkit.
namespace  ranges
 Semantic pipeline namespace for JH range operations.
namespace  conc
 Aggregated namespace for concurrency-aware resource containers.
namespace  avl
 Internal AVL-tree implementation namespace for jh::ordered_set and jh::ordered_map.
namespace  runtime_arr_helper
 Helper utilities and auxiliary types for jh::runtime_arr.
namespace  ipc
 Convenience alias for jh::sync::ipc.
namespace  jindallae
 Symbolic alias namespace for jh::meta.
namespace  macro
 Internal macro-based utilities.
namespace  meta
 Aggregated entry point for compile-time metaprogramming utilities.
namespace  pod
 Aggregated entry point for Plain-Old-Data and layout-stable value utilities.
namespace  typed
 Aggregated entry point for lightweight typing and semantic placeholder utilities.
namespace  serio
 Aggregated entry point for serialization and codec utilities.
namespace  sync
 Aggregated entry point for synchronization and coordination facilities.
namespace  views
 Convenience alias for jh::ranges::views.

Classes

struct  container_deduction
 User customization point for container element deduction. More...
struct  hash
 Behaviorally deduced hash functor. More...
struct  hash< T, std::enable_if_t< jh::concepts::has_std_hash< T > > >
 Case 1: std::hash<T> is valid. More...
struct  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  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...
struct  iterator
 Forward declaration of jh::iterator<Container>. More...
struct  recursive_registry
 Trait registry for detecting counting reentrance (recursive). More...
struct  reentrant_registry
 Trait registry for detecting idempotent (structural) reentrance. More...
struct  recursive_registry< std::recursive_mutex >
 Specialization for std::recursive_mutex. More...
struct  recursive_registry< std::recursive_timed_mutex >
 Specialization for std::recursive_timed_mutex. More...
struct  weak_ptr_hash
 Content-based hash functor for std::weak_ptr<T>. More...
struct  weak_ptr_eq
 Equality functor for std::weak_ptr<T>. More...
class  flat_multimap
 Flat ordered multimap implemented as a sorted contiguous container. More...
class  immutable_str
 Immutable string with optional automatic trimming and thread-safe hash caching. More...
struct  atomic_str_hash
 Custom hash functor for atomic_str_ptr and compatible types. More...
struct  atomic_str_eq
 Custom equality functor for atomic_str_ptr and compatible types. More...
class  runtime_arr
 A move-only, fixed-capacity array with runtime-determined length and RAII-based ownership. More...
class  runtime_arr< bool >
 Specialized implementation of jh::runtime_arr<bool> — a compact, bit-packed boolean array. More...
class  generator_range
 A range-like wrapper that enables iteration over a generator factory. More...

Concepts

concept  immutable_str_compatible
 Concept for types compatible with jh::immutable_str.

Typedefs

template<typename T>
using observe_pool
 Duck-typed alias of jh::conc::pointer_pool for content-based pooling of immutable objects.
template<typename Key, typename Value = jh::typed::monostate, typename Alloc = std::allocator<jh::conc::detail::value_t<Key, Value>>>
using resource_pool = jh::conc::flat_pool<Key, Value, jh::hash<Key>, Alloc>
 Convenience alias of jh::conc::flat_pool with behaviorally deduced hashing.
template<typename Key, typename Alloc = std::allocator<Key>>
using resource_pool_set = jh::conc::flat_pool<Key, jh::typed::monostate, jh::hash<Key>, Alloc>
 Set-style specialization of jh::resource_pool.
using atomic_str_ptr = std::shared_ptr<immutable_str>
 Atomically replaceable handle to an immutable string.
template<typename K, typename Alloc = std::allocator<K>>
using ordered_set
 Ordered associative set based on a contiguous-array AVL tree.
template<typename K, typename V, typename Alloc = std::allocator<std::pair<const K, V>>>
using ordered_map
 Ordered associative map based on a contiguous-array AVL tree.
template<typename T, typename U = typed::monostate>
using generator = async::generator<T, U>
 Alias of jh::async::generator in the root namespace.

Functions

template<typename F>
auto to_range (F &&f)
 Converts a generator factory (lambda or function) into a repeatable range.
template<concepts::sequence Seq>
decltype(auto) to_range (Seq &&s)
 Converts a sequence into a usable std::ranges::range object.
template<typename T>
atomic_str_ptr make_atomic (T str)=delete
atomic_str_ptr make_atomic (const char *str)
 Creates a shared pointer to an immutable_str.
template<jh::concepts::mutex_like M>
atomic_str_ptr safe_from (std::string_view sv, M &mtx)
 Creates a shared pointer to an immutable_str from a locked string view.
template<concepts::sequence SeqType>
generator< concepts::sequence_value_t< SeqType > > make_generator (const SeqType &seq)
 Alias of jh::async::make_generator.
template<typename T>
std::vector< T > to_vector (generator< T > &gen)
 Alias of jh::async::to_vector for generator-based conversion.
template<typename T>
std::deque< T > to_deque (generator< T > &gen)
 Alias of jh::async::to_deque for generator-based conversion.

Typedef Documentation

◆ atomic_str_ptr

using jh::atomic_str_ptr = std::shared_ptr<immutable_str>

Atomically replaceable handle to an immutable string.

An atomic_str_ptr is simply a std::shared_ptr<immutable_str>.

Since std::shared_ptr has built-in atomic operations (atomic_load, atomic_store, atomic_exchange, atomic_compare_exchange_*, as well as their *_explict forms) and jh::immutable_str is itself immutable, the pointer can be safely loaded, stored, or replaced across threads without any additional synchronization.

  • Atomicity is provided by std::shared_ptr (C++11+).
  • The underlying string never mutates, only the pointer changes.
  • Suitable for concurrent configuration, caches, and shared views.

◆ generator

template<typename T, typename U = typed::monostate>
using jh::generator = async::generator<T, U>

Alias of jh::async::generator in the root namespace.

This is a forwarding alias that exposes jh::async::generator<T, U> as jh::generator<T, U> for convenience.

See also
jh::async::generator

◆ observe_pool

template<typename T>
using jh::observe_pool
Initial value:
Weak pointer-observed pool for immutable or structurally immutable objects.
Definition pointer_pool.h:276
Equality functor for std::weak_ptr<T>.
Definition observe_pool.h:144

Duck-typed alias of jh::conc::pointer_pool for content-based pooling of immutable objects.

jh::observe_pool<T> provides logical deduplication of shared objects based on content hashing and equality. Objects are observed via std::weak_ptr and are never owned by the pool.

All concurrency, cleanup, and adaptive resizing behavior is defined entirely by jh::conc::pointer_pool, of which observe_pool is a direct alias with fixed template parameters.

Template Parameters
TThe pooled object type. T must be logically immutable, satisfy jh::concepts::extended_hashable, and support content-based operator==.
Note
Platform guidance:
All concurrent pools under <jh/pool> are designed primarily for POSIX platforms and rely on POSIX-style ordering semantics for their performance characteristics.
Windows (MinGW-w64 / MinGW-clang with UCRT or MSVCRT) is treated as a secondary platform. API compatibility is provided, but concurrency guarantees are not equivalent to POSIX builds. High-contention workloads are not recommended on Windows.
If your final deployment target is a POSIX system (Linux / Darwin), the pool implementations may be used as intended under full concurrency.

◆ ordered_map

template<typename K, typename V, typename Alloc = std::allocator<std::pair<const K, V>>>
using jh::ordered_map
Initial value:
Contiguous-array AVL tree used by jh::ordered_map and jh::ordered_set.
Definition ordered_map.h:663

Ordered associative map based on a contiguous-array AVL tree.

This alias provides an ordered map storing unique keys of type K and mapped values of type V. The semantics match those of std::map: keys are unique, elements are stored in sorted key order, and the mapped value is accessible via key lookup or iterator dereferencing. Internally this type is backed by avl::tree_map, using a contiguous storage layout rather than the pointer-based red-black tree used by STL maps.

Template Parameters
KKey type.
VMapped value type.
AllocAllocator used for internal node storage.

◆ ordered_set

template<typename K, typename Alloc = std::allocator<K>>
using jh::ordered_set
Initial value:

Ordered associative set based on a contiguous-array AVL tree.

This alias provides a set-like container storing unique keys of type K. The semantics match those of std::set: keys are unique, sorted in strictly increasing order, and no mapped value is stored. Internally this type is implemented using avl::tree_map with monostate as its value type, yielding a compact and allocation-free node layout.

Template Parameters
KKey type stored in the set.
AllocAllocator used for internal node storage.

◆ resource_pool

template<typename Key, typename Value = jh::typed::monostate, typename Alloc = std::allocator<jh::conc::detail::value_t<Key, Value>>>
using jh::resource_pool = jh::conc::flat_pool<Key, Value, jh::hash<Key>, Alloc>

Convenience alias of jh::conc::flat_pool with behaviorally deduced hashing.

jh::resource_pool<Key, Value, Alloc> is a direct alias of jh::conc::flat_pool that fixes the hash functor to jh::hash<Key>. No additional abstraction layer or duck-typing mechanism is introduced.

The alias relies on jh::hash<Key> to successfully resolve a hashing strategy for Key, following its resolution order: std::hash, ADL-discovered free hash(key), or key.hash().

This design preserves the full behavior and constraints of jh::conc::flat_pool while reducing template verbosity for the common case where no custom hash functor is required.

Template Parameters
KeyThe key type defining logical identity. Key must satisfy jh::concepts::extended_hashable and jh::concepts::is_contiguous_reallocable.
ValueThe value type stored in the pool. Must either be jh::typed::monostate or satisfy jh::concepts::is_contiguous_reallocable.
AllocAllocator used for internal storage. Defaults to an allocator compatible with the underlying flat_pool value representation.
Note
Design intent:
jh::resource_pool exists solely to reduce the cognitive and syntactic cost of using flat_pool in the common case.
When a nonstandard hashing strategy is required, users should instantiate jh::conc::flat_pool directly with an explicit hash functor.

◆ resource_pool_set

template<typename Key, typename Alloc = std::allocator<Key>>
using jh::resource_pool_set = jh::conc::flat_pool<Key, jh::typed::monostate, jh::hash<Key>, Alloc>

Set-style specialization of jh::resource_pool.

jh::resource_pool_set<Key> is an alias of jh::conc::flat_pool with Value fixed to jh::typed::monostate. It represents a concurrent pool of unique keys with no associated payload.

Function Documentation

◆ make_atomic()

atomic_str_ptr jh::make_atomic ( const char * str)
inline

Creates a shared pointer to an immutable_str.

Constructs a new jh::immutable_str instance from a null-terminated C-string and wraps it in a std::shared_ptr. This is the standard factory function for creating atomic, immutable string objects.

Parameters
strNull-terminated C-string to initialize from.
Returns
Shared pointer (atomic_str_ptr) managing the constructed immutable_str instance.
  • Performs a direct construction of immutable_str without intermediate copies or moves.
  • The returned object is reference-counted via std::shared_ptr and can be safely shared across threads.
  • Trimming behavior (if enabled) follows JH_IMMUTABLE_STR_AUTO_TRIM.
Note
  • Because immutable_str is non-copyable and non-movable, this factory is the only supported way to allocate it on the heap.
  • Once constructed, the lifetime of the string is bound to its std::shared_ptr instance.

◆ make_generator()

template<concepts::sequence SeqType>
generator< concepts::sequence_value_t< SeqType > > jh::async::make_generator ( const SeqType & seq)

Alias of jh::async::make_generator.

This function is re-exported from jh::async into the root namespace to allow construction of generators without qualifying the async namespace.

See also
jh::async::make_generator

◆ safe_from()

atomic_str_ptr jh::safe_from ( std::string_view sv,
M & mtx )
inline

Creates a shared pointer to an immutable_str from a locked string view.

Constructs a new jh::immutable_str using a std::string_view and an associated mutex-like object that guards the view's lifetime. This ensures thread-safe initialization from potentially mutable or shared buffers.

Template Parameters
MAny type satisfying jh::concepts::mutex_like, such as std::mutex, std::shared_mutex, or jh::typed::null_mutex_t.
Parameters
svString view referencing existing string data.
mtxMutex-like object protecting the lifetime of the structure that owns sv.
Returns
Shared pointer (atomic_str_ptr) managing the constructed immutable_str instance.
Exceptions
std::logic_errorIf sv contains embedded null ('\0') characters.
Warning
  • The caller must ensure that mtx correctly protects the memory region referenced by sv.
  • Providing an unrelated or unlocked mutex may result in undefined behavior.
Note
  • This overload is used when std::string_view refers to data from temporary, mutable, or shared contexts that require explicit synchronization.
  • When the data is guaranteed to be thread-local or immutable, jh::typed::null_mutex may be used for zero-cost locking.
  • Because immutable_str cannot be copied or moved, it must always be constructed via this factory or make_atomic().

◆ to_deque()

template<typename T>
std::deque< T > jh::async::to_deque ( generator< T > & gen)

Alias of jh::async::to_deque for generator-based conversion.

This function forwards jh::async::to_deque into the root namespace. In its current form, it operates on jh::async::generator-based sources and collects their yielded values into a std::deque.

Future overloads may extend this facility to additional source types. Overload resolution will rely on distinct parameter signatures, ensuring no ambiguity with the generator-based usage.

See also
jh::async::to_deque

◆ to_range() [1/2]

template<typename F>
auto jh::to_range ( F && f)

Converts a generator factory (lambda or function) into a repeatable range.

This helper transforms a callable object that returns jh::async::generator<T> (with U == typed::monostate) into a jh::async::generator_range<T>. The resulting object supports multiple independent iterations, since each call to begin() constructs a new generator instance.

The callable must take no arguments:

Any captured state must be enclosed within the lambda's closure. External parameters cannot be forwarded dynamically.

Template Parameters
FA callable returning jh::async::generator<T>.
Parameters
fA generator factory function (no arguments).
Returns
A repeatable, range-compatible wrapper for the generator.
See also
jh::async::generator_range

◆ to_range() [2/2]

template<concepts::sequence Seq>
decltype(auto) jh::to_range ( Seq && s)

Converts a sequence into a usable std::ranges::range object.

This is the user-facing interface for range conversion. It guarantees that any valid jh::concepts::sequence can be transformed into an object that models std::ranges::range, regardless of whether the original type is movable, copyable, or a simple sequence-like container.

The conversion is idempotent — if the input already models std::ranges::range and is safely movable or copyable, it is forwarded unchanged. Otherwise, the function wraps or adapts it internally to ensure range compatibility and reference safety.

Template Parameters
SeqA type satisfying jh::concepts::sequence.
Parameters
sThe input sequence to convert.
Returns
An object guaranteed to model std::ranges::range, ready for direct use in range-based for loops or std::ranges algorithms.

◆ to_vector()

template<typename T>
std::vector< T > jh::async::to_vector ( generator< T > & gen)

Alias of jh::async::to_vector for generator-based conversion.

This function forwards jh::async::to_vector into the root namespace. In its current form, it operates on jh::async::generator-based sources and materializes their yielded values into a std::vector.

Additional overloads may be introduced in the future to support other asynchronous or range-like sources. Such overloads will be distinguished by their parameter types and will not conflict with the generator-based form.

See also
jh::async::to_vector