Skip to content

Commit

Permalink
C++20 preparation: make operator != non-ambiguous.
Browse files Browse the repository at this point in the history
C++20 auto-generates the != operator from ==. However, if that
operator accepts a potentiallly different type, this might result in
an ambiguous operator (-Wambiguous-reversed-operator).
This provides the explicitly defined operator.
  • Loading branch information
hzeller committed Oct 10, 2023
1 parent e76eb27 commit bb56e57
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions common/util/tree_operations_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class SimpleNode {
void set_id(std::string&& new_id) { id_ = new_id; }

bool operator==(const ThisType& other) const { return this == &other; }
bool operator!=(const ThisType& other) const { return !(*this == other); }

friend std::ostream& operator<<(std::ostream& stream, const ThisType& self) {
self.PrintRecursively(stream, 0);
Expand Down

0 comments on commit bb56e57

Please sign in to comment.