From 6d1e684f8dd7f266708eb1fe0eec001a545ea89d Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 13 Jan 2017 00:33:21 -0500 Subject: [PATCH] optional emplacement. --- optional.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/optional.h b/optional.h index e3fbd12..9260cad 100644 --- a/optional.h +++ b/optional.h @@ -56,6 +56,10 @@ public: } + ~optional() { + reset(); + } + template< class U = T > optional& operator=( U&& value ) { @@ -82,9 +86,11 @@ public: return *this; } - - ~optional() { + template< class... Args > + void emplace( Args&&... args ) { reset(); + new(std::addressof(_data)) T(std::forward(args)...); + _engaged = true; }