Skip to content

Commit

Permalink
extend zip range
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Mar 27, 2024
1 parent ed68a53 commit 5cc3399
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/utl/zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ struct zip_iterator<std::tuple<Iterators...>> {
return *this;
}

SelfType& operator--() {
each_tup(its_, [](auto&& it) { --it; });
return *this;
}

bool operator==(SelfType const& rhs) const { return its_ == rhs.its_; }
bool operator!=(SelfType const& rhs) const { return its_ != rhs.its_; }
bool operator>(SelfType const& rhs) const { return its_ > rhs.its_; }
Expand Down Expand Up @@ -141,6 +146,18 @@ struct zip_range {

explicit zip_range(std::tuple<Containers...> tup) : tup_(std::move(tup)) {}

typename const_iterator::References operator[](std::size_t const i) const {
return *std::next(begin(),
static_cast<typename iterator::difference_type>(i));
}

typename iterator::References operator[](std::size_t const i) {
return *std::next(begin(),
static_cast<typename iterator::difference_type>(i));
}

std::size_t size() const { return std::get<0>(tup_).size(); }

const_iterator begin() const {
return const_iterator{
map_tup(tup_, [](auto&& c) { return std::begin(c); })};
Expand Down

0 comments on commit 5cc3399

Please sign in to comment.