|
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.
|
Forward declaration and duck-typed iterator concept definitions. More...
Go to the source code of this file.
Namespaces | |
| namespace | jh::concepts |
| Behavioral concept namespace of the JH Toolkit. | |
Concepts | |
| concept | jh::concepts::indirectly_readable |
| Concept for types that can be read indirectly via dereference. | |
| concept | jh::concepts::indirectly_writable |
| Concept for types that support indirect write operations through dereference. | |
| concept | jh::concepts::is_iterator |
| Concept for detecting iterator-like types based on behavior. | |
| concept | jh::concepts::sentinel_for |
| Concept for detecting sentinel-iterator compatibility. | |
| concept | jh::concepts::input_iterator |
| Concept for readable, comparable single-pass iterators. | |
| concept | jh::concepts::output_iterator |
| Concept for writable single-pass iterators. | |
| concept | jh::concepts::forward_iterator |
| Concept for multi-pass, readable, and self-sentinel iterators. | |
| concept | jh::concepts::bidirectional_iterator |
| Concept for iterators supporting bidirectional traversal. | |
| concept | jh::concepts::random_access_iterator |
| Concept for iterators supporting random access operations. | |
Typedefs | |
| template<typename I> | |
| using | jh::concepts::iterator_value_t = typename detail::iterator_value_impl<I>::type |
| Deduces the value type of a duck-typed iterator. | |
| template<typename I> | |
| using | jh::concepts::iterator_reference_t = typename detail::iterator_reference_impl<I>::type |
| Deduces the reference type of a duck-typed iterator. | |
| template<typename I> | |
| using | jh::concepts::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 | jh::concepts::iterator_difference_t = typename detail::iterator_difference_impl<I>::type |
| Deduces the difference type of a duck-typed iterator. | |
| 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. | |
Forward declaration and duck-typed iterator concept definitions.
This header defines the unified iterator interface and concept suite for the JH container framework. Unlike traditional STL iterators that rely on static typedefs such as iterator_category or difference_type, this design applies behavioral duck-typing — a type is recognized as an iterator if it behaves like one.
jh::iterator<> for cross-module compatibility. input_iterator, output_iterator, etc.). Behavioral Duck Typing
Iterators are recognized by behavior — valid expressions like *it, ++it, it++ — not by typedefs. Any type usable in for(auto&& x : container) qualifies, covering both for(auto& x : ...) and for(auto x : ...).
Unified Deduction Model
iterator_t<Container> resolves iterators by fallback: jh::Container<T>::type → Container::iterator → Container.begin() → T*raw pointer → T[]array decay.
STL Compatibility
Works with STL iterators, pointers, arrays, and custom duck-typed types, with no dependency on <iterator> or <ranges>.
Minimal Dependencies
Built only on <concepts>, <type_traits>, and <utility>. Traits and categories are deduced via valid expressions instead of std::iterator_traits.
Range Bridging
Reuses the same duck-typing model for jh::concepts::sequence and to_range(), enabling STL-style iteration for any non-destructive range-like type.
| Concept | Behavior Checked | Primary Use |
|---|---|---|
is_iterator | Basic iteration (*it, ++it) | Type detection |
indirectly_readable | Dereference validity and value/reference consistency | Readable element access |
indirectly_writable<Out, T> | Supports assignment through *it = value | Writable element access |
sentinel_for<S, I> | Equality/inequality comparability between iterator and sentinel | Range boundary detection |
input_iterator | Readable, comparable iteration; refines is_iterator and indirectly_readable | Single-pass sequential read |
output_iterator | Writable via *it = value; refines is_iterator and indirectly_writable | Single-pass sequential write |
forward_iterator | Refines input_iterator; multi-pass, copyable, and self-sentinel (sentinel_for<I, I>) | Stable, reentrant traversal |
bidirectional_iterator | Refines forward_iterator; supports reverse movement (–it, it–) | Reversible traversal |
random_access_iterator | Refines bidirectional_iterator; supports arithmetic and indexing (it + n, it[n]) | Contiguous or offset access |
iterator_t<T> | Unified iterator deduction via specialization, begin(), pointer, or array decay | Meta-type for resolving iterator type |
These definitions unify STL and custom iterator semantics under a single duck-typed system. A type is recognized as an iterator by behavioral conformance, not by static signature or inheritance.
1.3.x
2025