From 5b5e898afdca4966699344414890dbb5737e216a Mon Sep 17 00:00:00 2001 From: igor-anferov Date: Sat, 19 Oct 2024 18:45:24 +0100 Subject: [PATCH] GH-44464: [C++] Added rvalue-reference-qualified overload for arrow::Result::status() returning value instead of reference --- cpp/src/arrow/result.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/result.h b/cpp/src/arrow/result.h index 6786d2b3fcbf..091351154251 100644 --- a/cpp/src/arrow/result.h +++ b/cpp/src/arrow/result.h @@ -294,7 +294,18 @@ class [[nodiscard]] Result : public util::EqualityComparable> { /// /// \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"); + std::swap(status_, tmp); + return tmp; + } /// Gets the stored `T` value. /// @@ -350,7 +361,7 @@ class [[nodiscard]] Result : public util::EqualityComparable> { std::is_constructible::value>::type> Status Value(U* out) && { if (!ok()) { - return status(); + return std::move(*this).status(); } *out = U(MoveValueUnsafe()); return Status::OK(); @@ -380,7 +391,7 @@ class [[nodiscard]] Result : public util::EqualityComparable> { typename EnsureResult()(std::declval()))>::type Map( M&& m) && { if (!ok()) { - return status(); + return std::move(*this).status(); } return std::forward(m)(MoveValueUnsafe()); } @@ -402,7 +413,7 @@ class [[nodiscard]] Result : public util::EqualityComparable> { std::is_constructible::value>::type> Result As() && { if (!ok()) { - return status(); + return std::move(*this).status(); } return U(MoveValueUnsafe()); }