any: favor aggregate initialization upon construction

This commit is contained in:
Michele Caini
2021-04-02 17:20:41 +02:00
parent 76bf1791eb
commit 45cc24e0b8
2 changed files with 8 additions and 2 deletions

View File

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

View File

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