Add rtc::Optional::emplace

BUG=None

Review-Url: https://codereview.webrtc.org/2424063002
Cr-Commit-Position: refs/heads/master@{#14659}
This commit is contained in:
danilchap
2016-10-18 04:07:18 -07:00
committed by Commit bot
parent 7a3776102f
commit 9e83c97e9f
2 changed files with 195 additions and 0 deletions

View File

@ -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_; }