Fix implementation of optional<T&>::emplace()

This commit is contained in:
Deniz Evrenci
2019-07-08 19:32:17 +09:00
parent 084a9001f4
commit b074bee409

View File

@ -1982,15 +1982,12 @@ public:
return *this; return *this;
} }
/// Constructs the value in-place, destroying the current one if there is /// Rebinds this optional to `u`.
/// one. template <class U = T,
template <class... Args> T &emplace(Args &&... args) noexcept { detail::enable_if_t<!detail::is_optional<detail::decay_t<U>>::value>
static_assert(std::is_constructible<T, Args &&...>::value, * = nullptr>
"T must be constructible with Args"); optional &emplace(U &&u) noexcept {
return *this = std::forward<U>(u);
*this = nullopt;
this->construct(std::forward<Args>(args)...);
return value();
} }
void swap(optional &rhs) noexcept { std::swap(m_value, rhs.m_value); } void swap(optional &rhs) noexcept { std::swap(m_value, rhs.m_value); }