Skip to content

Commit

Permalink
Define operator!= in terms of operator== (gbdev#1659)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 authored Feb 15, 2025
1 parent b2e865e commit 62309d5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
3 changes: 2 additions & 1 deletion include/gfx/rgba.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ struct Rgba {
auto shl = [](uint8_t val, unsigned shift) { return static_cast<uint32_t>(val) << shift; };
return shl(red, 24) | shl(green, 16) | shl(blue, 8) | shl(alpha, 0);
}

bool operator==(Rgba const &rhs) const { return toCSS() == rhs.toCSS(); }
bool operator!=(Rgba const &rhs) const { return toCSS() != rhs.toCSS(); }
bool operator!=(Rgba const &rhs) const { return !operator==(rhs); }

// CGB colors are RGB555, so we use bit 15 to signify that the color is transparent instead
// Since the rest of the bits don't matter then, we return 0x8000 exactly.
Expand Down
7 changes: 2 additions & 5 deletions include/itertools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EnumSeq {
auto operator*() const { return _value; }

bool operator==(Iterator const &rhs) const { return _value == rhs._value; }
bool operator!=(Iterator const &rhs) const { return _value != rhs._value; }
bool operator!=(Iterator const &rhs) const { return !operator==(rhs); }
};

public:
Expand Down Expand Up @@ -59,10 +59,7 @@ class ZipIterator {
bool operator==(ZipIterator const &rhs) const {
return std::get<0>(_iters) == std::get<0>(rhs._iters);
}

bool operator!=(ZipIterator const &rhs) const {
return std::get<0>(_iters) != std::get<0>(rhs._iters);
}
bool operator!=(ZipIterator const &rhs) const { return !operator==(rhs); }
};

template<typename... Ts>
Expand Down
6 changes: 4 additions & 2 deletions src/gfx/pal_packing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ class AssignedProtos {
public:
Iter() = default;

bool operator==(Iter const &other) const { return _iter == other._iter; }
bool operator!=(Iter const &other) const { return !(*this == other); }
bool operator==(Iter const &rhs) const { return _iter == rhs._iter; }
bool operator!=(Iter const &rhs) const { return !operator==(rhs); }

Iter &operator++() {
++_iter;
skipEmpty();
Expand All @@ -98,6 +99,7 @@ class AssignedProtos {
++(*this);
return it;
}

reference operator*() const {
assume((*_iter).has_value());
return **_iter;
Expand Down
2 changes: 1 addition & 1 deletion src/gfx/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class Png {
}

bool operator==(Iterator const &rhs) const { return coords() == rhs.coords(); }
bool operator!=(Iterator const &rhs) const { return coords() != rhs.coords(); }
bool operator!=(Iterator const &rhs) const { return !operator==(rhs); }
};

public:
Expand Down

0 comments on commit 62309d5

Please sign in to comment.