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

Unified transform adaptor that dispatches between std::views::transform and jh::ranges::views::vis_transform. More...

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::transform_fn jh::ranges::views::transform {}
 The unified transform adaptor entry point.

Detailed Description

Unified transform adaptor that dispatches between std::views::transform and jh::ranges::views::vis_transform.

Author
JeongHan-Bae mastr.nosp@m.opse.nosp@m.udo@g.nosp@m.mail.nosp@m..com

The jh::ranges::views::transform adaptor performs a compile-time semantic dispatch between two transformation behaviors:

  • jh::ranges::views::vis_transform โ€” when the pair <R, F> satisfies jh::concepts::vis_function_for, meaning the range is non-consuming and the function is a pure observation (returns non-void).
  • std::views::transform โ€” otherwise, for standard consumptive transformations that may alter or terminate the underlying stream.

Design rationale

  • Problem: std::views::transform treats every projection as consumptive, even when it merely observes elements. This breaks reentrancy and forces intermediate buffering in non-consuming pipelines.
  • Solution: Defer dispatch until both R and F are known, so the adaptor can route to vis_transform only when the combination preserves observation semantics. This ensures correctness and efficiency.

Supports both direct and pipe usage forms:

Note
Dispatch occurs inside the call operator, because determining whether vis_transform semantics apply requires both the range and the callable type. This ensures that only non-consuming, pure-observation combinations are elevated to vis_transform, while all others fall back to the standard std::views::transform.
See also
jh::concepts::vis_function_for
jh::ranges::views::vis_transform
std::views::transform
Version
1.3.x
Date
2025