any: internal support for both aggreagates and non-aggregates (qol enhancement :)

This commit is contained in:
Michele Caini
2021-04-06 09:07:04 +02:00
parent d55cefc086
commit 5dbdb1bcb5

View File

@@ -178,9 +178,17 @@ class basic_any {
static_assert(sizeof...(Args) == 1u && (std::is_lvalue_reference_v<Args> && ...), "Invalid arguments");
instance = (std::addressof(args), ...);
} else if constexpr(in_situ<Type>) {
new (&storage) Type{std::forward<Args>(args)...};
if constexpr(std::is_aggregate_v<Type>) {
new (&storage) Type{std::forward<Args>(args)...};
} else {
new (&storage) Type(std::forward<Args>(args)...);
}
} else {
instance = new Type{std::forward<Args>(args)...};
if constexpr(std::is_aggregate_v<Type>) {
instance = new Type{std::forward<Args>(args)...};
} else {
instance = new Type(std::forward<Args>(args)...);
}
}
}
}