Răsfoiți Sursa

any: favor aggregate initialization upon construction

Michele Caini 4 ani în urmă
părinte
comite
45cc24e0b8
2 a modificat fișierele cu 8 adăugiri și 2 ștergeri
  1. 2 2
      src/entt/core/any.hpp
  2. 6 0
      test/entt/core/any.cpp

+ 2 - 2
src/entt/core/any.hpp

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

+ 6 - 0
test/entt/core/any.cpp

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