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::zip_view< Views > Class Template Referencefinal

A C++20-compatible implementation of std::ranges::zip_view. More...

#include <jh/ranges/zip_view.h>

Inheritance diagram for jh::ranges::zip_view< Views >:

Public Member Functions

 zip_view ()=default
 Default-constructs an empty zip_view.
constexpr zip_view (Views... vs)
 Constructs a zip_view from multiple views.
constexpr auto begin ()
 Returns an iterator to the beginning of the zipped sequence.
constexpr auto end ()
 Returns a sentinel marking the end of the zipped sequence.
constexpr auto begin () const
 Returns a const iterator to the beginning of the zipped sequence.
constexpr auto end () const
 Returns a const sentinel marking the end of the zipped sequence.

Detailed Description

template<std::ranges::view... Views>
class jh::ranges::zip_view< Views >

A C++20-compatible implementation of std::ranges::zip_view.

The zip_view class provides a view that aggregates multiple underlying ranges into synchronized tuples of elements, effectively iterating them in parallel. Each dereference yields a zip_reference_proxy holding references (or values) to the corresponding elements from all component ranges.

Iteration stops when any of the underlying ranges is exhausted, ensuring short-circuit semantics on the shortest input range.

The class follows the same observable semantics as std::ranges::zip_view (C++23), providing a transparent fallback implementation for C++20 environments.

Example:

std::vector<int> a = {1, 2, 3};
std::vector<char> b = {'A', 'B', 'C', 'D'};
jh::ranges::zip_view zipped(a, b);
for (const auto& [x, y] : zipped) {
std::cout << x << " : " << y << std::endl;
}
A C++20-compatible implementation of std::ranges::zip_view.
Definition zip_view.h:468
Template Parameters
ViewsParameter pack of underlying view types.
See also
jh::ranges::zip_iterator
jh::ranges::zip_sentinel
jh::ranges::zip_reference_proxy
jh::ranges::views::zip

Constructor & Destructor Documentation

◆ zip_view() [1/2]

template<std::ranges::view... Views>
jh::ranges::zip_view< Views >::zip_view ( )
default

Default-constructs an empty zip_view.

All underlying views are value-initialized.

◆ zip_view() [2/2]

template<std::ranges::view... Views>
jh::ranges::zip_view< Views >::zip_view ( Views... vs)
inlineexplicitconstexpr

Constructs a zip_view from multiple views.

Parameters
vsThe view objects to aggregate.

Each view is stored by value inside zip_view. The lifetime of these views determines the lifetime of their corresponding iterators and reference proxies.

Member Function Documentation

◆ begin() [1/2]

template<std::ranges::view... Views>
auto jh::ranges::zip_view< Views >::begin ( )
inlineconstexpr

Returns an iterator to the beginning of the zipped sequence.

Returns
A zip_iterator aggregating begin iterators of all underlying ranges.

This overload participates when *this is non-const.

◆ begin() [2/2]

template<std::ranges::view... Views>
auto jh::ranges::zip_view< Views >::begin ( ) const
inlineconstexpr

Returns a const iterator to the beginning of the zipped sequence.

Returns
A zip_iterator aggregating begin() iterators of all underlying ranges.

This overload participates when *this is const.

◆ end() [1/2]

template<std::ranges::view... Views>
auto jh::ranges::zip_view< Views >::end ( )
inlineconstexpr

Returns a sentinel marking the end of the zipped sequence.

Returns
A zip_sentinel aggregating end iterators of all underlying ranges.

Iteration stops when any of the component iterators reaches its corresponding end sentinel.

◆ end() [2/2]

template<std::ranges::view... Views>
auto jh::ranges::zip_view< Views >::end ( ) const
inlineconstexpr

Returns a const sentinel marking the end of the zipped sequence.

Returns
A zip_sentinel aggregating end() iterators of all underlying ranges.

This overload participates when *this is const.


The documentation for this class was generated from the following file: