Skip to content

Commit

Permalink
GH-44464: [C++] Added rvalue-reference-qualified overload for arrow::…
Browse files Browse the repository at this point in the history
…Result::status() returning value instead of reference
  • Loading branch information
igor-anferov committed Nov 3, 2024
1 parent 00e7c65 commit 5b5e898
Showing 1 changed file with 15 additions and 4 deletions.
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

0 comments on commit 5b5e898

Please sign in to comment.