Chromium Code Reviews| 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. |