Ensure that RTCErrorOr<T, E> doesn't require T to be default constructible
Bug: webrtc:15214
Change-Id: Ic2d61c64d770943472374f61ad71249e88c3f6f6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/307520
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Auto-Submit: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40223}
diff --git a/api/rtc_error.h b/api/rtc_error.h
index 00b0855..7adf30e 100644
--- a/api/rtc_error.h
+++ b/api/rtc_error.h
@@ -308,23 +308,23 @@
// the stack.
const T& value() const {
RTC_DCHECK(ok());
- return value_;
+ return *value_;
}
T& value() {
RTC_DCHECK(ok());
- return value_;
+ return *value_;
}
// Moves our current value out of this object and returns it, or DCHECK-fails
// if !this->ok().
T MoveValue() {
RTC_DCHECK(ok());
- return std::move(value_);
+ return std::move(*value_);
}
private:
RTCError error_;
- T value_;
+ absl::optional<T> value_;
};
} // namespace webrtc