-
Notifications
You must be signed in to change notification settings - Fork 4.2k
ARROW-16743: [C++] Add short-circuit version of logical Status AND #13304
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,6 +150,8 @@ class ARROW_MUST_USE_TYPE ARROW_EXPORT Status : public util::EqualityComparable< | |
| // AND the statuses. | ||
| inline Status operator&(const Status& s) const noexcept; | ||
| inline Status operator&(Status&& s) const noexcept; | ||
| inline Status operator&&(const Status& s) const noexcept; | ||
| inline Status operator&&(Status&& s) const noexcept; | ||
| inline Status& operator&=(const Status& s) noexcept; | ||
| inline Status& operator&=(Status&& s) noexcept; | ||
|
|
||
|
|
@@ -424,6 +426,22 @@ Status Status::operator&(Status&& s) const noexcept { | |
| } | ||
| } | ||
|
|
||
| Status Status::operator&&(const Status& s) const noexcept { | ||
| if (ok()) { | ||
| return s; | ||
| } else { | ||
| return *this; | ||
| } | ||
| } | ||
|
|
||
| Status Status::operator&&(Status&& s) const noexcept { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: doesn't it make sense if we combine these two overloads into one function accepting a value parameter? As
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that having a non-reference parameter is preferable. We might still want two overloads, however, since we're copying in the case that Status Status::operator&&(Status s) const& noexcept {
if (!ok()) return *this;
return s;
}
Status Status::operator&&(Status s) && noexcept {
if (!ok()) return std::move(*this);
return s;
} |
||
| if (ok()) { | ||
| return std::move(s); | ||
| } else { | ||
| return *this; | ||
| } | ||
| } | ||
|
|
||
| Status& Status::operator&=(const Status& s) noexcept { | ||
| if (ok() && !s.ok()) { | ||
| CopyFrom(s); | ||
|
|
||
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.
To me,
&&is easier to understand. Just like a bash script, I know LHS will be evaluated before RHS, and RHS will only be evaluated if LHS is true.