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
zip.h File Reference

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.

Detailed Description

Extended zip view adaptor compatible with jh::concepts::sequence.

Author
JeongHan-Bae <mastropseudo@gmail.com>

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:

Summary of design goals:

  • Extend zip to all jh::concepts::sequence-compatible types.
  • Preserve the C++23 behavioral contract for single-argument pipelines.
  • Offer a clean, opt-in extension (zip_pipe) for multi-argument pipeline usage.

Typical usage:

using namespace jh::ranges::views;
// Standard usage (same as C++23):
for (auto [x, y] : zip(a, b)) { ... }
for (auto [x, y] : a | zip(b)) { ... }
// Extended multi-sequence pipe:
for (auto [x, y, z] : a | zip_pipe(b, c)) { ... }
Range view adaptor implementations with explicit semantic control.
Definition common.h:99
constexpr detail::zip_pipe_fn zip_pipe
Extended multi-argument zip adaptor for pipe syntax.
Definition zip.h:317
constexpr detail::zip_fn zip
The user-facing zip adaptor.
Definition zip.h:291

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.

Version
1.3.x
Date
2025