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