-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix EnumeratorHandle compilation #5109
Conversation
Signed-off-by: Bili Dong <[email protected]>
0349a7f
to
010c503
Compare
@@ -630,6 +631,11 @@ const EnumeratorHandle<T> &EnumeratorHandle<T>::operator++() { | |||
return *this; | |||
} | |||
|
|||
template <typename T> | |||
bool EnumeratorHandle<T>::operator==(const EnumeratorHandle<T> &other) const { | |||
return !(*this != other); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the noise comment, but is this way of defining operator==
common in C++?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually the opposite (operator!=
is implemented from operator==
), however, here we already having operator!=
with quite peculiar semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually the opposite (
operator!=
is implemented fromoperator==
),
Indeed, with C++20, you don't even need to do that -- if you define operator==
, the compiler will synthesize operator!=
for you
@@ -630,6 +631,11 @@ const EnumeratorHandle<T> &EnumeratorHandle<T>::operator++() { | |||
return *this; | |||
} | |||
|
|||
template <typename T> | |||
bool EnumeratorHandle<T>::operator==(const EnumeratorHandle<T> &other) const { | |||
return !(*this != other); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is as good as can be done, but the (existing) EnumeratorHandle::operator!=
right after this looks suspect to me.
@@ -630,6 +631,11 @@ const EnumeratorHandle<T> &EnumeratorHandle<T>::operator++() { | |||
return *this; | |||
} | |||
|
|||
template <typename T> | |||
bool EnumeratorHandle<T>::operator==(const EnumeratorHandle<T> &other) const { | |||
return !(*this != other); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually the opposite (
operator!=
is implemented fromoperator==
),
Indeed, with C++20, you don't even need to do that -- if you define operator==
, the compiler will synthesize operator!=
for you
Fixes #5107.