any: favor aggregate initialization upon construction
This commit is contained in:
@@ -181,9 +181,9 @@ public:
|
||||
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)...);
|
||||
new (&storage) Type{std::forward<Args>(args)...};
|
||||
} else {
|
||||
instance = new Type(std::forward<Args>(args)...);
|
||||
instance = new Type{std::forward<Args>(args)...};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -917,3 +917,9 @@ TEST(Any, Alignment) {
|
||||
entt::basic_any<alignment, alignment> sbo[2] = { over_aligned{}, over_aligned{} };
|
||||
test(sbo, [](auto *pre, auto *post) { ASSERT_NE(pre, post); });
|
||||
}
|
||||
|
||||
TEST(Any, AggregatesMustWork) {
|
||||
struct aggregate_type { int value; };
|
||||
// the goal of this test is to enforce the requirements for aggregate types
|
||||
entt::any{std::in_place_type<aggregate_type>, 42}.emplace<aggregate_type>(42);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user