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

Behavioral concept namespace of the JH Toolkit. More...

Classes

struct  range_storage_traits
 Trait defining how a range (or equivalent) is held inside a view or wrapper. More...

Concepts

concept  closable_container_for
 Concept checking whether a container C can be directly constructed ("closed") from a range R.
concept  collectable_container_for
 Concept verifying that a container C can collect elements from a range R via incremental insertion.
concept  is_contiguous_reallocable
 Concept that constrains types usable in contiguous, reallocating containers.
concept  has_std_hash
 Checks whether std::hash<T> is valid and callable.
concept  has_adl_hash
 Checks whether a free (ADL-discoverable) hash() function exists.
concept  has_mbr_hash
 Checks whether a type defines a hash() member function.
concept  extended_hashable
 Concept for types that can be hashed through any supported mechanism.
concept  indirectly_readable
 Concept for types that can be read indirectly via dereference.
concept  indirectly_writable
 Concept for types that support indirect write operations through dereference.
concept  is_iterator
 Concept for detecting iterator-like types based on behavior.
concept  sentinel_for
 Concept for detecting sentinel-iterator compatibility.
concept  input_iterator
 Concept for readable, comparable single-pass iterators.
concept  output_iterator
 Concept for writable single-pass iterators.
concept  forward_iterator
 Concept for multi-pass, readable, and self-sentinel iterators.
concept  bidirectional_iterator
 Concept for iterators supporting bidirectional traversal.
concept  random_access_iterator
 Concept for iterators supporting random access operations.
concept  basic_lockable
 Concept for basic lockable objects.
concept  excl_lockable
 Concept for exclusive lockable objects supporting try semantics.
concept  timed_excl_lockable
 Concept for timed exclusive lockable objects.
concept  shared_lockable
 Concept for shared (reader) lockable objects.
concept  timed_shared_lockable
 Concept for shared lockables supporting timed acquisition.
concept  mutex_like
 General mutex-like concept.
concept  timed_mutex_like
 Timed variant of mutex_like.
concept  rw_mutex_like
 Read-write (RW) mutex concept.
concept  recursive_mutex
 Concept for counting reentrant (recursive) mutexes.
concept  reentrant_mutex
 Concept for idempotent (structurally reentrant) mutexes.
concept  reentrance_capable_mutex
 Concept for any mutex supporting some form of reentrance.
concept  vis_function_for
 Concept describing the visual relation between a range and a callable.
concept  sequence
 Concept that checks whether a type provides at least const (non-destructive) iteration.
concept  tuple_like
 Concept recognizing tuple-like types.
concept  pair_like_for
 Checks whether a type P is a 2-element tuple-like whose element types exactly match K and V (after remove_cvref).

Typedefs

template<typename C>
using container_value_t = typename detail::container_value_type_impl<C>::type
 Deduce the value type of a container C.
template<typename I>
using iterator_value_t = typename detail::iterator_value_impl<I>::type
 Deduces the value type of a duck-typed iterator.
template<typename I>
using iterator_reference_t = typename detail::iterator_reference_impl<I>::type
 Deduces the reference type of a duck-typed iterator.
template<typename I>
using iterator_rvalue_reference_t = decltype(detail::adl_iter_move(std::declval<I &>()))
 Deduces the rvalue reference type of a duck-typed iterator.
template<typename I>
using iterator_difference_t = typename detail::iterator_difference_impl<I>::type
 Deduces the difference type of a duck-typed iterator.
template<typename Container>
using iterator_t = typename detail::iterator_resolver<Container>::type
 Deduces the iterator type associated with a container, pointer, or array.
template<typename T>
using sequence_value_t = typename detail::sequence_value_type_impl<T>::type
 Extracts the element type of a sequence.
template<sequence Seq>
using sequence_difference_t
 Deduce the difference_type used by a sequence after range adaptation.

Variables

template<typename T>
constexpr bool is_sequence = sequence<T>
 Compile-time check for sequence compliance.
constexpr std::uint16_t max_pod_array_bytes
 Maximum size of a POD array (16KB). This is a compile-time constant.
constexpr std::uint16_t max_pod_bitflags_bytes
 Maximum allowed size of a POD bitflags structure: 4KB (4096 bytes).
template<typename C>
constexpr jh::pod::pair< data_status, len_status > linear_status
 Precomputed linear-container classification result.

Detailed Description

Behavioral concept namespace of the JH Toolkit.

jh::concepts defines the behavioral foundation layer of the JH Toolkit. It contains C++20 concepts and associated traits used to recognize types by observable behavior rather than inheritance, nominal typing, or explicit base classes.

This namespace serves as the canonical semantic base for higher-level modules, including asynchronous facilities, range adaptation, container construction, synchronization primitives, and POD modeling.

All concepts exposed here are intended to be:

  • Purely compile-time and constexpr-friendly
  • Duck-typed and expression-based
  • Free of RTTI and runtime inspection
  • Stable within a given Major.Minor.x version series

Higher-level APIs should depend on jh::concepts to express semantic intent and enforce constraints, rather than encoding ad-hoc SFINAE logic or implementation-specific checks.

Typedef Documentation

◆ container_value_t

template<typename C>
using jh::concepts::container_value_t = typename detail::container_value_type_impl<C>::type

Deduce the value type of a container C.

Resolution rules:

  1. If jh::container_deduction<C>::value_type is explicitly defined, it overrides all other deduction mechanisms.
  2. Otherwise, deduction proceeds using the following logic:
    • If only C::value_type exists, it is used.
    • If only iterator deduction (iterator_t and iterator_value_t) is available, it is used.
    • If both C::value_type and iterator deduction exist, they must not conflict. If they share a common reference type, the declared C::value_type is selected.
  3. If no valid deduction is possible, the result is void.
Note
When using a proxy reference type within an iterator, the proxy should be implicitly convertible to the iterator's value_type to ensure correct participation in generic deduction. For full interoperability, it is recommended to register explicit std::common_reference specializations as follows:
template<> struct std::common_reference<ProxyT, T> { using type = T; };
template<> struct std::common_reference<T, ProxyT> { using type = T; };
template<> struct std::common_reference<ProxyT, ProxyT> { using type = ProxyT; };

For completeness, derived forms should be added for reference and rvalue combinations, inheriting from the base forms:

template<> struct std::common_reference<ProxyT&, T&>
: std::common_reference<ProxyT, T> {};
template<> struct std::common_reference<ProxyT&&, T&&>
: std::common_reference<ProxyT, T> {};
// and T, ProxyT swapped forms, ProxyT with itself, etc.

This ensures that proxy iterators remain compatible with generic range-based algorithms and container deduction mechanisms.

Template Parameters
CThe container type to deduce from.
Returns
The deduced element type or void if deduction fails.

◆ iterator_t

template<typename Container>
using jh::concepts::iterator_t = typename detail::iterator_resolver<Container>::type

Deduces the iterator type associated with a container, pointer, or array.

iterator_t<Container> provides a unified iterator deduction path for all iterable entities supported by the JH Toolkit. It cooperates with jh::iterator<Container>, which serves as the non-intrusive extension point for third-party containers.

Unified Deduction Model

iterator_t<Container> selects the iterator in the following order:

  1. jh::iterator<Container>::type
  2. Container::iterator
  3. decltype(Container.begin())
  4. T* (raw pointer)
  5. T[N] or T[] decayed to T*

This mechanism ensures consistent iterator semantics across standard containers, duck-typed containers, pointers, and arrays, while allowing external iterator declarations for non-modifiable third-party types.

Template Parameters
ContainerThe type whose iterator is to be deduced.

◆ sequence_difference_t

template<sequence Seq>
using jh::concepts::sequence_difference_t
Initial value:
std::ranges::range_difference_t<decltype(jh::to_range(std::declval<Seq &>()))>

Deduce the difference_type used by a sequence after range adaptation.

This alias evaluates the difference_type that would be observed by STL algorithms after converting a jh::concepts::sequence into a valid std::ranges::range via jh::to_range().

In effect, it represents the type actually used by standard range-based algorithms for distance and offset calculations. Since every legal range must define a valid difference type, this alias is always well-formed.

If the original sequence does not provide a deducible difference type, the internal range_adaptor automatically falls back to std::ptrdiff_t to ensure STL algorithm compatibility.

Template Parameters
SeqA type satisfying jh::concepts::sequence.

◆ sequence_value_t

template<typename T>
using jh::concepts::sequence_value_t = typename detail::sequence_value_type_impl<T>::type

Extracts the element type of a sequence.

Resolves the value_type through jh::concepts::iterator_t<T>. Cleanses cv-ref qualifiers for consistent deduction.

Template Parameters
TThe sequence type.

Variable Documentation

◆ is_sequence

template<typename T>
bool jh::concepts::is_sequence = sequence<T>
constexpr

Compile-time check for sequence compliance.

Equivalent to jh::concepts::sequence<T>, provided as a boolean constant for generic metaprogramming.

Template Parameters
TThe type to check.

◆ linear_status

template<typename C>
jh::pod::pair<data_status, len_status> jh::pod::detail::linear_status
constexpr

Precomputed linear-container classification result.

This variable template evaluates the compile-time data/length access pattern of a given container type C via compute_view_status<C>(), and caches its pair of data_status / len_status for reuse.

ADL Priority:
Detection prioritizes ADL (Argument-Dependent Lookup) forms such as get_data() or get_size() before checking direct fields or member functions. This allows users to explicitly override default detection when the internal representation is ambiguous or does not meet expectations.

Exposure:
The result is exposed in jh::concepts as jh::concepts::linear_status<C>, enabling higher-level modules to query whether a type provides pointer-based and length-based accessors without repeating introspection.

Note:
The precomputed status is exposed instead of the function compute_view_status<C>() to minimize compile-time overhead. The constexpr evaluation runs once per type, and subsequent concept checks reuse the cached value.