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

Unified Diff: webrtc/base/optional.h

Issue 2424063002: Add rtc::Optional::emplace (Closed)
Patch Set: Feedback 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 1bcfd1a8c2fbd00e2a470c1140cc8d57a8b276f4..728ed9e7378c07ce4b2c0c89edecfc497c14c4f7 100644
--- a/webrtc/base/optional.h
+++ b/webrtc/base/optional.h
@@ -193,6 +193,16 @@ class Optional final {
PoisonValue();
}
+ template <class... Args>
+ void emplace(Args&&... args) {
+ if (has_value_)
+ value_.~T();
+ else
+ UnpoisonValue();
+ new (&value_) T(std::forward<Args>(args)...);
+ has_value_ = true;
+ }
+
// 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