Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from 2 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
17 changes: 13 additions & 4 deletions fml/status_or.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ namespace fml {
template <typename T>
class StatusOr {
public:
// These constructors are intended be compatible with absl::status_or.
// NOLINTBEGIN(google-explicit-constructor)

StatusOr(const T& value) : status_(), value_(value) {}
StatusOr(const Status& status) : status_(status), value_() {}

// NOLINTEND(google-explicit-constructor)

StatusOr(const StatusOr&) = default;
StatusOr(StatusOr&&) = default;

Expand Down Expand Up @@ -63,13 +68,17 @@ class StatusOr {
bool ok() const { return status_.ok(); }

const T& value() const {
FML_CHECK(status_.ok());
return value_.value();
if (status_.ok()) {
return value_.value();
}
FML_LOG(FATAL) << "StatusOr::value() called on error Status";
}

T& value() {
FML_CHECK(status_.ok());
return value_.value();
if (status_.ok()) {
return value_.value();
}
FML_LOG(FATAL) << "StatusOr::value() called on error Status";
}

private:
Expand Down