Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Unified Diff: webrtc/base/optional.h

Issue 2942203002: Add has_value() and value() methods to rtc::Optional. (Closed)
Patch Set: Reorder declarations Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/base/optional_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/optional.h
diff --git a/webrtc/base/optional.h b/webrtc/base/optional.h
index c8ed069d55570b1f6bf5e7191bcf121626dd0a0b..4f883a886295fad3867d5293bf60f788dc2366b4 100644
--- a/webrtc/base/optional.h
+++ b/webrtc/base/optional.h
@@ -218,6 +218,7 @@ class Optional final {
// Conversion to bool to test if we have a value.
explicit operator bool() const { return has_value_; }
+ bool has_value() const { return has_value_; }
// Dereferencing. Only allowed if we have a value.
const T* operator->() const {
@@ -236,6 +237,14 @@ class Optional final {
RTC_DCHECK(has_value_);
return value_;
}
+ const T& value() const {
+ RTC_DCHECK(has_value_);
+ return value_;
+ }
+ T& value() {
+ RTC_DCHECK(has_value_);
+ return value_;
+ }
// Dereference with a default value in case we don't have a value.
const T& value_or(const T& default_val) const {
« no previous file with comments | « no previous file | webrtc/base/optional_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698