Browse Source

meta: use meta_any context aware constructors if possible

Michele Caini 3 years ago
parent
commit
4901188409
2 changed files with 7 additions and 12 deletions
  1. 1 4
      src/entt/meta/meta.hpp
  2. 6 8
      src/entt/meta/node.hpp

+ 1 - 4
src/entt/meta/meta.hpp

@@ -606,10 +606,7 @@ meta_any make_meta(Args &&...args) {
  */
 template<typename Type>
 meta_any forward_as_meta(const meta_ctx &ctx, Type &&value) {
-    // TODO it would be great if we had value and context construction support for meta_any
-    meta_any elem{meta_ctx_arg, ctx};
-    elem.emplace<Type &&>(std::forward<Type>(value));
-    return elem;
+    return meta_any{ctx, std::in_place_type<Type &&>, std::forward<Type>(value)};
 }
 
 /**

+ 6 - 8
src/entt/meta/node.hpp

@@ -173,10 +173,7 @@ template<typename Type>
 void meta_default_constructor([[maybe_unused]] meta_type_node &node) {
     if constexpr(std::is_default_constructible_v<Type>) {
         node.default_constructor = +[](const meta_ctx &ctx) {
-            // TODO it would be great if we had value and context construction support for meta_any
-            meta_any elem{meta_ctx_arg, ctx};
-            elem.emplace<Type>();
-            return elem;
+            return meta_any{ctx, std::in_place_type<Type>};
         };
     }
 }
@@ -198,10 +195,11 @@ template<typename Type>
 void meta_from_void([[maybe_unused]] meta_type_node &node) {
     if constexpr(!std::is_same_v<Type, void> && !std::is_function_v<Type>) {
         node.from_void = +[](const meta_ctx &ctx, void *element, const void *as_const) {
-            // TODO it would be great if we had value and context construction support for meta_any
-            meta_any elem{meta_ctx_arg, ctx};
-            element ? elem.emplace<std::decay_t<Type> &>(*static_cast<std::decay_t<Type> *>(element)) : elem.emplace<const std::decay_t<Type> &>(*static_cast<const std::decay_t<Type> *>(as_const));
-            return elem;
+            if(element) {
+                return meta_any{ctx, std::in_place_type<std::decay_t<Type> &>, *static_cast<std::decay_t<Type> *>(element)};
+            }
+
+            return meta_any{ctx, std::in_place_type<const std::decay_t<Type> &>, *static_cast<const std::decay_t<Type> *>(as_const)};
         };
     }
 }