Chromium Code Reviews

Unified Diff: webrtc/base/optional.h

Issue 2432393002: Add rtc::Optional equality/unequality comparisions with object (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« 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..767f3dc2edc55ef4503489ace229bbb28368c7e0 100644
--- a/webrtc/base/optional.h
+++ b/webrtc/base/optional.h
@@ -234,8 +234,7 @@ 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_;
@@ -244,6 +243,18 @@ class Optional final {
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& 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_;
+ }
kwiberg-webrtc 2016/10/19 11:16:42 Maybe do all the operator== before the operator!=
danilchap 2016/10/19 11:23:52 Good point. Done.
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