|
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.
|
Extended zip view adaptor compatible with jh::concepts::sequence.
More...
#include <ranges>#include <cstdint>#include "jh/conceptual/sequence.h"#include "jh/ranges/zip_view.h"Go to the source code of this file.
Namespaces | |
| namespace | jh::ranges |
| Semantic pipeline namespace for JH range operations. | |
| namespace | jh::ranges::views |
| Range view adaptor implementations with explicit semantic control. | |
Variables | |
| constexpr detail::zip_fn | jh::ranges::views::zip {} |
The user-facing zip adaptor. | |
| constexpr detail::zip_pipe_fn | jh::ranges::views::zip_pipe {} |
| Extended multi-argument zip adaptor for pipe syntax. | |
Extended zip view adaptor compatible with jh::concepts::sequence.
This header provides jh::ranges::views::zip — a conceptually aligned but generalized version of the C++23 std::views::zip adaptor. It extends the applicability of zip to custom jh::concepts::sequence types, which may not be standard ranges but still define explicit iteration semantics (non-consuming begin/end pairs).
The resulting view type is jh::ranges::zip_view, which models both std::ranges::view and jh::concepts::sequence. This dual compatibility allows seamless interoperability between STL-style range adaptors and jh-specific abstractions.
Behavior overview:
jh::ranges::views::zip(a, b, c) constructs and returns a jh::ranges::zip_view directly, just like C++23 std::views::zip. a | jh::ranges::views::zip(b) is supported, producing a zip_view<a,b>. This exactly matches the standard C++23 behavior — only one right-hand sequence is allowed. jh::ranges::views::zip_pipe enables piping with multiple right-hand sequences, e.g.: a | jh::ranges::views::zip_pipe(b, c, d). This is a semantic extension of the standard pipeline form, generalized for jh::concepts::sequence sources. It preserves full compositional compatibility while providing broader applicability. Summary of design goals:
zip to all jh::concepts::sequence-compatible types. zip_pipe) for multi-argument pipeline usage. Typical usage:
About jh::concepts::sequence and compatibility:
The jh::concepts::sequence abstraction is designed to enable third-party or non-standard containers to participate naturally in the range adaptor ecosystem. It recognizes any type that supports non-consuming iteration — that is, a const-accessible begin() and a deducible end() (including static sentinels). Such types can be safely iterated multiple times without altering or consuming their internal state, and are thus considered valid sequences.
Unlike a typical "range wrapper" system, this layer is active and semantic: containers that model std::ranges::range and are movable or copyable are forwarded directly. Non-movable and non-copyable ranges (e.g. jh::runtime_arr<T>) are proxied by std::ranges::subrange to ensure safe reference semantics. For other sequence-like types that do not formally model std::ranges::range, jh::to_range() constructs a jh::ranges::range_adaptor, which actively completes missing iterator traits and category tags through jh::ranges::detail::completed_iterator.
As a result, any valid sequence — even a type lacking standard iterator typedefs — can be semantically promoted into a fully compliant std::ranges::range via jh::to_range(seq). All jh::ranges::views adaptors, including zip and zip_pipe, perform this proxying step automatically, ensuring that user-defined sequence-like containers can directly participate in both standard and extended range pipelines.
1.3.x
2025