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 Namespace Reference

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

Detailed Description

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.

See also
jh::views

Function Documentation

◆ collect_adaptor()

template<typename C, std::ranges::range R>
auto jh::ranges::collect_adaptor ( R && r)
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:

  • insert() — for associative containers (e.g. std::set).
  • emplace() — for emplace-enabled containers (e.g. std::unordered_set).
  • emplace_back() — for sequence containers (e.g. std::vector, std::deque).

If the container supports reserve() and the range models sized_range, capacity is preallocated automatically.

Template Parameters
CThe target container type to be constructed.
RThe input range type to be materialized.
Parameters
rThe input range instance to be collected.
Returns
A fully constructed container C containing all elements from r.
Note
This function forms the core of the collect pipeline adaptor. In most user code, it is preferable to use jh::ranges::collect<C> directly instead of invoking this function manually.

◆ get()

template<std::size_t I, typename... Elems>
decltype(auto) jh::ranges::get ( const zip_reference_proxy< Elems... > & p)
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.

Template Parameters
IThe index of the element to retrieve.
ElemsParameter pack of stored element types.
Parameters
pThe zip_reference_proxy instance to access.
Returns
The I-th element reference from the proxy.
See also
jh::ranges::zip_reference_proxy
std::get

◆ to_adaptor()

template<typename C, std::ranges::range R, typename... Args>
auto jh::ranges::to_adaptor ( R && r,
Args &&... args )
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.

Template Parameters
CThe target container type.
RThe input range type.
ArgsAdditional constructor argument types for C.
Parameters
rThe source range.
argsOptional forwarded constructor arguments for C.
Returns
A fully constructed container C.
Note
This function forms the core implementation used by both direct calls and the pipe-style to<C>() adaptor.

◆ tuple_transform()

template<typename F, typename Tuple>
auto jh::ranges::tuple_transform ( F && f,
Tuple && t )
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.

Template Parameters
FCallable type — must be invocable with each element of Tuple.
TupleThe tuple-like type to be transformed.
Parameters
fThe callable to apply to each element.
tThe tuple whose elements are to be transformed.
Returns
A new std::tuple containing f(get<i>(t)) for each element.
Note
This function preserves value category:
  • Lvalue elements are forwarded as references.
  • Rvalue elements are moved when possible.

◆ zip_view()

template<std::ranges::viewable_range... Rs>
jh::ranges::zip_view ( Rs && ...) -> zip_view< std::views::all_t< Rs >... >

Deduction guide for jh::ranges::zip_view.

Template Parameters
RsThe range types to be zipped.

Allows automatic template argument deduction when constructing a zip_view directly.

Variable Documentation

◆ adapt

detail::adapt_fn jh::ranges::adapt {}
inlineconstexpr

The user-facing adapt adaptor.

Provides both direct and pipeline conversion of any jh::concepts::sequence into a viewable range.

Acts as a bridge between jh::concepts::sequence and the C++23 std::ranges ecosystem.

Note
Some types already model 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.
Passing non-copyable or non-movable ranges or any non-standard sequences through 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.
Once adapted, these ranges can participate freely in std::views pipelines or jh::ranges::views adaptors.
See also
jh::to_range
jh::concepts::sequence

◆ collect

template<typename C>
collect_fn<C> jh::ranges::collect {}
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:

Note

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.

Template Parameters
CThe container type to collect into.
See also
jh::ranges::to
jh::ranges::collect_fn

◆ to

template<typename C>
to_fn<C> jh::ranges::to {}
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:

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.

Note
Use jh::ranges::collect instead if the range is not directly closable to the target container or involves non-copyable proxy views.
Template Parameters
CThe container type to construct.
See also
jh::ranges::collect
jh::ranges::to_fn