Skip to content

Commit

Permalink
Fix productIterator
Browse files Browse the repository at this point in the history
The algorithms really enforce that the iterator must return a reference.
  • Loading branch information
rprospero committed Apr 23, 2024
1 parent e5e0886 commit e4081ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/classes/productIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ bool ProductIterator::operator==(const ProductIterator &other) const { return x_

bool ProductIterator::operator!=(const ProductIterator &other) const { return x_ != other.x_ || y_ != other.y_; }

ProductIterator::value_type ProductIterator::operator*() { return {x_, y_}; }
ProductIterator::reference ProductIterator::operator*() {
internal_ = std::make_tuple<>(x_, y_);
return internal_;
}

ProductIterator &ProductIterator::operator++()
{
Expand Down
3 changes: 2 additions & 1 deletion src/classes/productIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ProductIterator
{
private:
int x_, y_, xSize_, ySize_;
std::tuple<int, int> internal_;
int toIndex() const;
void fromIndex(int);

Expand All @@ -24,7 +25,7 @@ class ProductIterator

ProductIterator begin() const;
ProductIterator end() const;
value_type operator*();
reference operator*();
value_type operator[](difference_type i) const;

difference_type operator-(const ProductIterator &it) const;
Expand Down

0 comments on commit e4081ff

Please sign in to comment.