From b074bee4096ef174c5f966fa4a6e046dad956c0d Mon Sep 17 00:00:00 2001 From: Deniz Evrenci Date: Mon, 8 Jul 2019 19:32:17 +0900 Subject: [PATCH] Fix implementation of optional::emplace() --- include/tl/optional.hpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/include/tl/optional.hpp b/include/tl/optional.hpp index 9cba0b8..ad8ae2f 100644 --- a/include/tl/optional.hpp +++ b/include/tl/optional.hpp @@ -1982,15 +1982,12 @@ public: return *this; } - /// Constructs the value in-place, destroying the current one if there is - /// one. - template T &emplace(Args &&... args) noexcept { - static_assert(std::is_constructible::value, - "T must be constructible with Args"); - - *this = nullopt; - this->construct(std::forward(args)...); - return value(); + /// Rebinds this optional to `u`. + template >::value> + * = nullptr> + optional &emplace(U &&u) noexcept { + return *this = std::forward(u); } void swap(optional &rhs) noexcept { std::swap(m_value, rhs.m_value); }