mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
fix optional: add in-place construction, emplace assignment
This commit is contained in:
parent
a77fd5ffef
commit
e5efbfe340
2 changed files with 178 additions and 51 deletions
|
@ -151,6 +151,23 @@ namespace sprout {
|
|||
return *this;
|
||||
}
|
||||
|
||||
template<
|
||||
typename... Args,
|
||||
typename = typename std::enable_if<std::is_constructible<T, Args&&...>::value>::type
|
||||
>
|
||||
void emplace(Args&&... args) {
|
||||
optional temp(sprout::in_place, sprout::forward<Args>(args)...);
|
||||
temp.swap(*this);
|
||||
}
|
||||
template<
|
||||
typename U, typename... Args,
|
||||
typename = typename std::enable_if<std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value>::type
|
||||
>
|
||||
void emplace(std::initializer_list<U> il, Args&&... args) {
|
||||
optional temp(sprout::in_place, il, sprout::forward<Args>(args)...);
|
||||
temp.swap(*this);
|
||||
}
|
||||
|
||||
void assign(sprout::nullopt_t) SPROUT_NOEXCEPT {
|
||||
destroy();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue