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::ranges::views Namespace Reference

Range view adaptor implementations with explicit semantic control. More...

Variables

constexpr detail::common_fn common {}
 User-facing common adaptor instance.
constexpr detail::enumerate_fn enumerate {}
 The user-facing enumerate adaptor.
constexpr detail::flatten_fn flatten {}
 User-facing flatten adaptor.
constexpr detail::transform_fn transform {}
 The unified transform adaptor entry point.
constexpr detail::vis_transform_fn vis_transform {}
 The user-facing vis_transform adaptor.
constexpr detail::zip_fn zip {}
 The user-facing zip adaptor.
constexpr detail::zip_pipe_fn zip_pipe {}
 Extended multi-argument zip adaptor for pipe syntax.

Detailed Description

Range view adaptor implementations with explicit semantic control.

The jh::ranges::views namespace contains the complete implementation of JH Toolkit's range view adaptors.
This layer extends the standard C++ ranges/view model with explicit, engineering-oriented semantics for traversal, projection, and composition. In particular, it distinguishes between consuming and non-consuming behaviors, preserves reentrancy where applicable, and enables structure-aware pipeline construction.
All view adaptors provided by the toolkit are defined here. Any flattened or convenience entry points (such as jh::views) forward directly to this namespace without introducing additional abstraction or behavior.

Variable Documentation

◆ common

detail::common_fn jh::ranges::views::common {}
inlineconstexpr

User-facing common adaptor instance.

Provides both direct and pipeline forms:

For details on behavior and semantics, see detail::common_fn.

◆ enumerate

detail::enumerate_fn jh::ranges::views::enumerate {}
inlineconstexpr

The user-facing enumerate adaptor.

Provides a unified interface for enumerating a sequence with indices, implemented as a jh::ranges::zip_view combining an index std::views::iota with the given sequence. Supports both direct and pipe syntax:

The starting index can be optionally specified; defaults to 0 if omitted:

See also
jh::ranges::views::zip

◆ flatten

detail::flatten_fn jh::ranges::views::flatten {}
inlineconstexpr

User-facing flatten adaptor.

Provides a unified interface for flattening tuple-like elements within a range. The adaptor is lazy and purely observational: tuple-like elements are wrapped into jh::meta::flatten_proxy objects, while other elements are forwarded unchanged.

Supports both direct and pipe usage forms:

Behavior:

  • Each element is inspected lazily; if it models jh::concepts::tuple_like, it is wrapped into jh::meta::flatten_proxy.
  • Non-tuple-like elements are left untouched.
  • The adaptor delegates to jh::ranges::views::transform, which automatically preserves the consumption behavior of the input range:
    • If the source is non-consuming, the result remains reentrant.
    • If the source is consuming, the result remains single-pass.
  • No ownership or lifetime semantics are altered.
Note
The flatten adaptor determines flattenability purely by duck typing: any object that supports structured binding is recursively expanded.
The following are recognized as part of the framework's standard set of tuple-like types to prevent accidental misuse:
User-defined POD or aggregate types that do not declare structured binding are never flattened and are treated as atomic values. Flattening applies only to types that explicitly declare structured binding.
Because such a declaration requires explicit std specialization, it cannot occur accidentally. Therefore, declaring structured binding is considered explicit permission for recursive deconstruction, consistent with jh::concepts::tuple_like.
See also
jh::meta::flatten_proxy
jh::ranges::views::transform
jh::concepts::tuple_like

◆ transform

detail::transform_fn jh::ranges::views::transform {}
inlineconstexpr

The unified transform adaptor entry point.

Provides an adaptive interface for transformation within range pipelines. The adaptor performs a deferred semantic inspection of the pair <R, F> to determine whether to use the non-consuming or consumptive transformation path.

Supports both direct and pipe usage forms:

Note
The dispatch is performed per combination of range and callable. Non-consuming ranges with purely observational projections automatically gain vis_transform semantics and remain reentrant. All others use std::views::transform to preserve correct consumption semantics.

◆ vis_transform

detail::vis_transform_fn jh::ranges::views::vis_transform {}
inlineconstexpr

The user-facing vis_transform adaptor.

Provides an explicit, non-consuming transform adaptor for observation-only projections. Unlike std::views::transform, this adaptor preserves reentrancy whenever possible.

Supports both direct and pipe usage forms:

The adaptor enforces the concept jh::concepts::vis_function_for<F, R>, which requires that the callable is safely invocable for every element of R and returns a non-void result.

Design semantics

  • All projections are non-consuming and reentrant by design.
  • Intended for explicit use in analytical or visualization pipelines.
  • Integrates directly with jh::ranges::views::common() and jh::ranges::to for final materialization.
Note
When combined with jh::ranges::views::common(), a vis_transform-based pipeline can be materialized directly into a container via jh::ranges::to — no intermediate collect() is required.
See also
jh::ranges::vis_transform_view
jh::concepts::vis_function_for
jh::ranges::views::transform
jh::ranges::views::common
jh::ranges::to

◆ zip

detail::zip_fn jh::ranges::views::zip {}
inlineconstexpr

The user-facing zip adaptor.

Provides a unified interface for zipping multiple sequences into a jh::ranges::zip_view. Supports both direct and pipe syntax:

◆ zip_pipe

detail::zip_pipe_fn jh::ranges::views::zip_pipe {}
inlineconstexpr

Extended multi-argument zip adaptor for pipe syntax.

Supports:

Note
The zip_pipe adaptor resolves the inherent ambiguity of the standard zip adaptor: in C++23, zip(a, b) returns a zip_view, while zip(b) produces a closure. This makes multi-argument pipeline forms (a | zip(b, c)) impossible.

The zip_pipe variant explicitly defines a closure-only behavior, enabling expressive and unambiguous syntax:

auto z1 = a | jh::ranges::views::zip(b); // standard form
auto z2 = a | jh::ranges::views::zip_pipe(b,c); // extended multi-sequence form
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

Conceptually, zip_pipe is not a new feature, but a semantic resolution: it restores closure semantics for multi-argument zip operations while maintaining full compatibility with the C++23 range adaptor model.