forked from TartanLlama/optional
Fix implementation of optional<T&>::emplace()
This commit is contained in:
@ -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); }
|
||||||
|
Reference in New Issue
Block a user