Index: webrtc/base/optional.h |
diff --git a/webrtc/base/optional.h b/webrtc/base/optional.h |
index 25cfbfe41752597d340864f3cc46ce56794763b4..add6fa9181b192f15aa33163972a42c1be26e31b 100644 |
--- a/webrtc/base/optional.h |
+++ b/webrtc/base/optional.h |
@@ -62,10 +62,10 @@ class Optional final { |
Optional() : has_value_(false) {} |
// Construct an Optional that contains a value. |
- explicit Optional(const T& value) : has_value_(true) { |
+ Optional(const T& value) : has_value_(true) { |
tommi
2016/06/16 16:08:22
this goes against the style guide though. Is requ
kwiberg-webrtc
2016/06/16 17:26:42
It's very convenient to have T convert implicitly
|
new (&value_) T(value); |
} |
- explicit Optional(T&& value) : has_value_(true) { |
+ Optional(T&& value) : has_value_(true) { |
new (&value_) T(std::move(value)); |
} |
@@ -186,6 +186,22 @@ class Optional final { |
: m1.has_value_ != m2.has_value_; |
} |
+ friend bool operator==(const Optional& opt, const T& val) { |
+ return opt.has_value_ && opt.value_ == val; |
+ } |
+ |
+ friend bool operator==(const T& val, const Optional& opt) { |
+ return opt == val; |
+ } |
+ |
+ friend bool operator!=(const Optional& opt, const T& val) { |
+ return !(opt == val); |
+ } |
+ |
+ friend bool operator!=(const T& val, const Optional& opt) { |
+ return !(opt == val); |
+ } |
+ |
private: |
bool has_value_; // True iff value_ contains a live value. |
union { |