1
0
Fork 0
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:
bolero-MURAKAMI 2013-05-23 20:55:26 +09:00
parent a77fd5ffef
commit e5efbfe340
2 changed files with 178 additions and 51 deletions

View file

@ -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();
}