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

Unified Diff: webrtc/base/optional.h

Issue 2432393002: Add rtc::Optional equality/unequality comparisions with object (Closed)
Patch Set: Feedback Created 4 years, 2 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 728ed9e7378c07ce4b2c0c89edecfc497c14c4f7..ec33470f26754a868ce56cef35a189dfc6f8ab69 100644
--- a/webrtc/base/optional.h
+++ b/webrtc/base/optional.h
@@ -234,16 +234,28 @@ class Optional final {
}
// Equality tests. Two Optionals are equal if they contain equivalent values,
- // or
- // if they're both empty.
+ // or if they're both empty.
friend bool operator==(const Optional& m1, const Optional& m2) {
return m1.has_value_ && m2.has_value_ ? m1.value_ == m2.value_
: m1.has_value_ == m2.has_value_;
}
+ friend bool operator==(const Optional& opt, const T& value) {
+ return opt.has_value_ && opt.value_ == value;
+ }
+ friend bool operator==(const T& value, const Optional& opt) {
+ return opt.has_value_ && value == opt.value_;
+ }
+
friend bool operator!=(const Optional& m1, const Optional& m2) {
return m1.has_value_ && m2.has_value_ ? m1.value_ != m2.value_
: m1.has_value_ != m2.has_value_;
}
+ friend bool operator!=(const Optional& opt, const T& value) {
+ return !opt.has_value_ || opt.value_ != value;
+ }
+ friend bool operator!=(const T& value, const Optional& opt) {
+ return !opt.has_value_ || value != opt.value_;
+ }
private:
// Tell sanitizers that value_ shouldn't be touched.
« 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