22#ifndef _ITERTOOLS_ZIP_HPP
23#define _ITERTOOLS_ZIP_HPP
46 template <
typename... Iters>
47 struct zip_iter : iterator_facade<zip_iter<Iters...>, std::tuple<typename std::iterator_traits<Iters>::value_type...>> {
49 std::tuple<Iters...>
its;
62 template <
size_t... Is> [[gnu::always_inline]]
void increment_all(std::index_sequence<Is...>) { ((void)(++std::get<Is>(
its)), ...); }
66 void increment() { increment_all(std::index_sequence_for<Iters...>{}); }
87 return [&]<
size_t... Is>(std::index_sequence<Is...>) {
88 return ((std::get<Is>(
its) == std::get<Is>(s.
it)) || ...);
89 }(std::index_sequence_for<Iters...>{});
94 template <
size_t... Is> [[nodiscard]]
auto tuple_map_impl(std::index_sequence<Is...>)
const {
95 return std::tuple<decltype(*std::get<Is>(
its))...>(*std::get<Is>(
its)...);
103 [[nodiscard]]
decltype(
auto)
dereference()
const {
return tuple_map_impl(std::index_sequence_for<Iters...>{}); }
114 template <
typename... Rs>
struct zipped {
116 std::tuple<Rs...>
tu;
119 using seq_t = std::index_sequence_for<Rs...>;
133 template <
typename... Us>
zipped(Us &&...rgs) :
tu{std::forward<Us>(rgs)...} {}
140 template <
typename F,
size_t... Is> [[gnu::always_inline]]
auto tuple_map(F &&f, std::index_sequence<Is...>) {
141 return std::make_tuple(std::forward<F>(f)(std::get<Is>(
tu))...);
145 template <
typename F,
size_t... Is> [[gnu::always_inline]]
auto tuple_map(F &&f, std::index_sequence<Is...>)
const {
146 return std::make_tuple(std::forward<F>(f)(std::get<Is>(
tu))...);
155 return tuple_map([](
auto &&rg) {
return std::begin(rg); },
seq_t{});
160 return tuple_map([](
auto &&rg) {
return std::cbegin(rg); },
seq_t{});
170 [[nodiscard]]
auto end() noexcept {
175 [[nodiscard]]
auto cend() const noexcept {
180 [[nodiscard]]
auto end() const noexcept {
return cend(); }
218 template <
typename... Rs> [[nodiscard]]
zipped<Rs...>
zip(Rs &&...rgs) {
return {std::forward<Rs>(rgs)...}; }
zipped< Rs... > zip(Rs &&...rgs)
Lazy-zip ranges together (similar to Python's zip).
sentinel_t< Iter > make_sentinel(Iter it)
Create an itertools::sentinel_t from an iterator using template type deduction.
Provides a CRTP base class for various iterator types in itertools.
Provides a generic sentinel type for various iterator types in itertools.