|
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.
|
Semantic pipeline namespace for JH range operations. More...
Namespaces | |
| namespace | views |
| Range view adaptor implementations with explicit semantic control. | |
Classes | |
| class | range_adaptor |
| Lightweight adapter that exposes any sequence as a standard range. More... | |
| struct | collect_fn |
Function object implementing jh::ranges::collect. More... | |
| struct | to_fn |
Function object implementing jh::ranges::to. More... | |
| class | vis_transform_view |
| A non-consuming transform view preserving reentrancy. More... | |
| struct | zip_reference_proxy |
Aggregates element references for a single tuple in jh::ranges::zip_view. More... | |
| struct | is_zip_proxy |
| struct | is_zip_proxy< class zip_reference_proxy< Ts... > > |
| struct | zip_proxy_value_tuple |
| struct | zip_proxy_value_tuple< class zip_reference_proxy< Ts... > > |
| struct | zip_sentinel |
Sentinel type for jh::ranges::zip_view. More... | |
| struct | zip_iterator |
Iterator type for jh::ranges::zip_view. More... | |
| class | zip_view |
A C++20-compatible implementation of std::ranges::zip_view. More... | |
Typedefs | |
| template<typename T> | |
| using | zip_proxy_value_tuple_t = typename zip_proxy_value_tuple<T>::type |
Functions | |
| template<typename Seq> | |
| range_adaptor (Seq &&) -> range_adaptor< Seq > | |
| template<typename C, std::ranges::range R> | |
| constexpr auto | collect_adaptor (R &&r) |
Core implementation for jh::ranges::collect adaptor. | |
| template<typename C, std::ranges::range R, typename... Args> | |
| constexpr auto | to_adaptor (R &&r, Args &&... args) |
Core implementation for jh::ranges::to adaptor. | |
| template<typename R, typename F> | |
| vis_transform_view (R &&, F) -> vis_transform_view< std::views::all_t< R >, F > | |
Deduction guide for vis_transform_view. | |
| template<typename F, typename Tuple> | |
| constexpr auto | tuple_transform (F &&f, Tuple &&t) |
Applies a callable to each element of a std::tuple. | |
| template<std::size_t I, typename... Elems> | |
| constexpr decltype(auto) | get (const zip_reference_proxy< Elems... > &p) noexcept |
Retrieves the I-th element from a zip_reference_proxy. | |
| template<typename... Iters, typename... Sentinels> | |
| constexpr bool | operator== (const zip_sentinel< Sentinels... > &s, const zip_iterator< Iters... > &it) |
| template<typename... Iters, typename... Sentinels> | |
| constexpr bool | operator!= (const zip_sentinel< Sentinels... > &s, const zip_iterator< Iters... > &it) |
| template<std::ranges::viewable_range... Rs> | |
| zip_view (Rs &&...) -> zip_view< std::views::all_t< Rs >... > | |
Deduction guide for jh::ranges::zip_view. | |
Variables | |
| constexpr detail::adapt_fn | adapt {} |
The user-facing adapt adaptor. | |
| template<typename C> | |
| constexpr collect_fn< C > | collect {} |
Global instance of the collect adaptor. | |
| template<typename C> | |
| constexpr to_fn< C > | to {} |
Global instance of the to adaptor. | |
| template<typename T> | |
| constexpr bool | is_zip_proxy_v = is_zip_proxy<T>::value |
Semantic pipeline namespace for JH range operations.
jh::ranges contains the pipeline closure objects used in range expressions (e.g. adapt, collect, to), as well as internal helper utilities that support those closures.
Only the pipeline closures are intended for direct use. Helper types inside this namespace are implementation details and are typically accessed indirectly through the exported closures.
To use view adaptors, include <jh/views> and use jh::views.
To use pipeline / materialization closures, include <jh/ranges_ext> and use jh::ranges.
|
constexpr |
Core implementation for jh::ranges::collect adaptor.
Performs eager materialization of a range R into container C.
If C and R satisfy jh::concepts::closable_container_for<C, R>, the operation directly delegates to jh::ranges::to_adaptor<C> for optimal construction. Otherwise, it iterates through the range and fills C using one of the available mechanisms:
std::set). std::unordered_set). std::vector, std::deque). If the container supports reserve() and the range models sized_range, capacity is preallocated automatically.
| C | The target container type to be constructed. |
| R | The input range type to be materialized. |
| r | The input range instance to be collected. |
C containing all elements from r.collect pipeline adaptor. In most user code, it is preferable to use jh::ranges::collect<C> directly instead of invoking this function manually.
|
constexprnoexcept |
Retrieves the I-th element from a zip_reference_proxy.
This free function provides tuple-like access to elements within a zip_reference_proxy, enabling structured bindings and compatibility with std::get and std::tuple_element.
Internally, this simply forwards to p.get<I>(), preserving reference semantics and ensuring that both direct and wrapped elements yield proper references.
| I | The index of the element to retrieve. |
| Elems | Parameter pack of stored element types. |
| p | The zip_reference_proxy instance to access. |
I-th element reference from the proxy.
|
constexpr |
Core implementation for jh::ranges::to adaptor.
Constructs a container C from range R when the pair satisfies the closable_container_for concept. This includes direct iterator constructors, move iterators, vector bridging, and adapter-based composition (e.g. std::stack<std::deque<T>>).
This function is selected only if the relationship between C and R can be established at compile time. Otherwise, use jh::ranges::collect as a more permissive fallback.
| C | The target container type. |
| R | The input range type. |
| Args | Additional constructor argument types for C. |
| r | The source range. |
| args | Optional forwarded constructor arguments for C. |
C.to<C>() adaptor.
|
constexpr |
Applies a callable to each element of a std::tuple.
This helper function iterates over all elements of a tuple and applies the provided callable f to each element, returning a new std::tuple containing the transformed results.
It is implemented using std::index_sequence expansion and perfect forwarding. This utility serves as a C++20-compatible equivalent to std::apply for element-wise transformation.
| F | Callable type — must be invocable with each element of Tuple. |
| Tuple | The tuple-like type to be transformed. |
| f | The callable to apply to each element. |
| t | The tuple whose elements are to be transformed. |
std::tuple containing f(get<i>(t)) for each element.| jh::ranges::zip_view | ( | Rs && | ... | ) | -> zip_view< std::views::all_t< Rs >... > |
Deduction guide for jh::ranges::zip_view.
| Rs | The range types to be zipped. |
Allows automatic template argument deduction when constructing a zip_view directly.
|
inlineconstexpr |
The user-facing adapt adaptor.
Provides both direct and pipeline conversion of any jh::concepts::sequence into a viewable range.
auto r = jh::ranges::adapt(seq); auto r = seq | jh::ranges::adapt(); Acts as a bridge between jh::concepts::sequence and the C++23 std::ranges ecosystem.
std::ranges::range but are non-copyable or non-movable. Such ranges cannot satisfy std::ranges::viewable_range, and thus cannot be used directly with std::views::* adaptors. adapt (or equivalently jh::to_range()) constructs a safe proxy — typically a std::ranges::subrange or jh::ranges::range_adaptor — that restores viewable_range compatibility. std::views pipelines or jh::ranges::views adaptors.
|
inlineconstexpr |
Global instance of the collect adaptor.
This is the primary user-facing interface for range materialization. It supports both direct and pipe usage styles:
Supports both direct and pipe usage forms:
auto v = jh::ranges::collect<std::vector<int>>(input); auto v = range | jh::ranges::collect<std::vector<int>>(); Recommendation:
If your goal is to explicitly materialize a lazy pipeline, std::vector is usually the best target container — it provides optimal contiguous storage and can be seamlessly passed to a subsequent to<C> stage for further conversion.
| C | The container type to collect into. |
|
inlineconstexpr |
Global instance of the to adaptor.
This is the primary user-facing entry point for constructing containers from compatible ranges. It supports both direct and pipe invocation forms:
auto s = jh::ranges::to<std::set<int>>(v); auto dq = v | jh::ranges::to<std::deque<int>>(); The adaptor automatically distinguishes between these two forms by analyzing the argument category: when the first argument is a range, it performs an immediate container construction; otherwise, it returns a lightweight closure object suitable for pipe composition.
This behavior is intentional and specification-safe — no valid standard container constructor ever accepts two independent ranges, therefore this heuristic introduces no ambiguity for normal user code.
jh::ranges::collect instead if the range is not directly closable to the target container or involves non-copyable proxy views.| C | The container type to construct. |