Просмотр исходного кода

meta_ctor: remove overload that accepts meta_any* (wip)

skypjack 2 недель назад
Родитель
Сommit
674de9dfa3
2 измененных файлов с 7 добавлено и 17 удалено
  1. 0 1
      TODO
  2. 7 16
      src/entt/meta/meta.hpp

+ 0 - 1
TODO

@@ -38,5 +38,4 @@ TODO:
 * meta_data should check arity on set/get
 * refine arg and arity on meta_data
 * remove meta invoke/set/get that take meta_any *const args
-* remove meta construct that takes meta_any *const args
 * meta: meta_data set/get_arity and set/get_arg or similar

+ 7 - 16
src/entt/meta/meta.hpp

@@ -1321,35 +1321,26 @@ public:
     }
 
     /**
-     * @brief Creates an instance of the underlying type, if possible.
+     * @copybrief construct
      * @param args Parameters to use to construct the instance.
-     * @param sz Number of parameters to use to construct the instance.
      * @return A wrapper containing the new instance, if any.
      */
-    [[nodiscard]] meta_any construct(meta_any *const args, const size_type sz) const {
+    [[nodiscard]] meta_any construct(auto &&...args) const {
+        stl::array<meta_any, sizeof...(args)> all{meta_any{*ctx, stl::forward<decltype(args)>(args)}...};
+
         if(const auto &ref = fetch_node(); ref.details) {
-            if(const auto *candidate = lookup(args, sz, false, [first = ref.details->ctor.cbegin(), last = ref.details->ctor.cend()]() mutable { return first == last ? nullptr : &*(first++); }); candidate) {
-                return candidate->invoke(*ctx, args);
+            if(const auto *candidate = lookup(all.data(), all.size(), false, [first = ref.details->ctor.cbegin(), last = ref.details->ctor.cend()]() mutable { return first == last ? nullptr : &*(first++); }); candidate) {
+                return candidate->invoke(*ctx, all.data());
             }
         }
 
-        if(const auto &ref = fetch_node(); (sz == 0u) && (ref.default_constructor != nullptr)) {
+        if(const auto &ref = fetch_node(); all.empty() && (ref.default_constructor != nullptr)) {
             return ref.default_constructor(*ctx);
         }
 
         return meta_any{meta_ctx_arg, *ctx};
     }
 
-    /**
-     * @copybrief construct
-     * @param args Parameters to use to construct the instance.
-     * @return A wrapper containing the new instance, if any.
-     */
-    [[nodiscard]] meta_any construct(auto &&...args) const {
-        return construct(stl::array<meta_any, sizeof...(args)>{meta_any{*ctx, stl::forward<decltype(args)>(args)}...}.data(), sizeof...(args));
-        // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
-    }
-
     /**
      * @brief Wraps an opaque element of the underlying type.
      * @param elem A valid pointer to an element of the underlying type.