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

Unified Diff: webrtc/base/optional.h

Issue 2426473004: Add rtc::Optional::reset (Closed)
Patch Set: ... 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 b047fabc427871ee9d86fdc3f7ef6397c0f82a46..1bcfd1a8c2fbd00e2a470c1140cc8d57a8b276f4 100644
--- a/webrtc/base/optional.h
+++ b/webrtc/base/optional.h
@@ -132,10 +132,8 @@ class Optional final {
new (&value_) T(m.value_); // T's copy constructor.
has_value_ = true;
}
- } else if (has_value_) {
- value_.~T();
- has_value_ = false;
- PoisonValue();
+ } else {
+ reset();
}
return *this;
}
@@ -152,10 +150,8 @@ class Optional final {
new (&value_) T(std::move(m.value_)); // T's move constructor.
has_value_ = true;
}
- } else if (has_value_) {
- value_.~T();
- has_value_ = false;
- PoisonValue();
+ } else {
+ reset();
}
return *this;
}
@@ -188,6 +184,15 @@ class Optional final {
}
}
+ // Destroy any contained value. Has no effect if we have no value.
+ void reset() {
+ if (!has_value_)
+ return;
+ value_.~T();
+ has_value_ = false;
+ PoisonValue();
+ }
+
// Conversion to bool to test if we have a value.
explicit operator bool() const { return has_value_; }
« 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