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