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

Unified Diff: webrtc/base/optional.h

Issue 2072713002: Made rtc::Optional a bit more like std::optional. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 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 | no next file » | 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 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 {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698