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}
This commit is contained in:
Florent Castelli 2023-06-02 15:57:43 +00:00 committed by WebRTC LUCI CQ
parent 0740048170
commit be316dab88

View file

@ -308,23 +308,23 @@ class RTCErrorOr {
// 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