Skip to content
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

GH-44464: [C++] Added rvalue-reference-qualified overload for arrow::Result::status() returning value instead of reference #44477

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions cpp/src/arrow/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,18 @@ class [[nodiscard]] Result : public util::EqualityComparable<Result<T>> {
///
/// \return The stored non-OK status object, or an OK status if this object
/// has a value.
constexpr const Status& status() const { return status_; }
constexpr const Status& status() const& { return status_; }

/// Gets the stored status object, or an OK status if a `T` value is stored.
///
/// \return The stored non-OK status object, or an OK status if this object
/// has a value.
Status status() && {
if (ok()) return Status::OK();
auto tmp = Status::UnknownError("Uninitialized Result<T>");
std::swap(status_, tmp);
return tmp;
}

/// Gets the stored `T` value.
///
Expand Down Expand Up @@ -350,7 +361,7 @@ class [[nodiscard]] Result : public util::EqualityComparable<Result<T>> {
std::is_constructible<U, T>::value>::type>
Status Value(U* out) && {
if (!ok()) {
return status();
return std::move(*this).status();
}
*out = U(MoveValueUnsafe());
return Status::OK();
Expand Down Expand Up @@ -380,7 +391,7 @@ class [[nodiscard]] Result : public util::EqualityComparable<Result<T>> {
typename EnsureResult<decltype(std::declval<M&&>()(std::declval<T&&>()))>::type Map(
M&& m) && {
if (!ok()) {
return status();
return std::move(*this).status();
}
return std::forward<M>(m)(MoveValueUnsafe());
}
Expand All @@ -402,7 +413,7 @@ class [[nodiscard]] Result : public util::EqualityComparable<Result<T>> {
std::is_constructible<U, T>::value>::type>
Result<U> As() && {
if (!ok()) {
return status();
return std::move(*this).status();
}
return U(MoveValueUnsafe());
}
Expand Down
Loading