Răsfoiți Sursa

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

Michele Caini 4 ani în urmă
părinte
comite
5dbdb1bcb5
1 a modificat fișierele cu 10 adăugiri și 2 ștergeri
  1. 10 2
      src/entt/core/any.hpp

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

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