Jelajahi Sumber

meta: general renaming, size -> arity when it returns the arity of a function

Michele Caini 5 tahun lalu
induk
melakukan
a8d95b284d

+ 0 - 1
TODO

@@ -18,7 +18,6 @@
   - ...
 
 WIP:
-* HP: meta func/ctor size -> arity
 * HP: as_ref should be a qualified function, not a global one (no breaking change, ADL makes it work anyway)
 * HP: merge view and view pack
 * HP: invalid view auto-refresh

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

@@ -508,7 +508,7 @@ public:
 
         internal::meta_func_node **it = &type->func;
         for(; *it && (*it)->id != id; it = &(*it)->next);
-        for(; *it && (*it)->id == id && (*it)->size < node.size; it = &(*it)->next);
+        for(; *it && (*it)->id == id && (*it)->arity < node.arity; it = &(*it)->next);
 
         node.id = id;
         node.next = *it;

+ 14 - 14
src/entt/meta/meta.hpp

@@ -682,8 +682,8 @@ struct meta_ctor {
      * @brief Returns the number of arguments accepted by a constructor.
      * @return The number of arguments accepted by the constructor.
      */
-    [[nodiscard]] size_type size() const ENTT_NOEXCEPT {
-        return node->size;
+    [[nodiscard]] size_type arity() const ENTT_NOEXCEPT {
+        return node->arity;
     }
 
     /**
@@ -704,7 +704,7 @@ struct meta_ctor {
      * @return A meta any containing the new instance, if any.
      */
     [[nodiscard]] meta_any invoke(meta_any * const args, const size_type sz) const {
-        return sz == size() ? node->invoke(args) : meta_any{};
+        return sz == arity() ? node->invoke(args) : meta_any{};
     }
 
     /**
@@ -872,8 +872,8 @@ struct meta_func {
      * @brief Returns the number of arguments accepted by a member function.
      * @return The number of arguments accepted by the member function.
      */
-    [[nodiscard]] size_type size() const ENTT_NOEXCEPT {
-        return node->size;
+    [[nodiscard]] size_type arity() const ENTT_NOEXCEPT {
+        return node->arity;
     }
 
     /**
@@ -921,7 +921,7 @@ struct meta_func {
      * @return A meta any containing the returned value, if any.
      */
     meta_any invoke(meta_handle instance, meta_any * const args, const size_type sz) const {
-        return sz == size() ? node->invoke(std::move(instance), args) : meta_any{};
+        return sz == arity() ? node->invoke(std::move(instance), args) : meta_any{};
     }
 
     /**
@@ -992,7 +992,7 @@ class meta_type {
     template<typename... Args, auto... Index>
     [[nodiscard]] static const internal::meta_ctor_node * ctor(const internal::meta_ctor_node *curr, std::index_sequence<Index...>) {
         for(; curr; curr = curr->next) {
-            if(curr->size == sizeof...(Args) && (can_cast_or_convert(internal::meta_info<Args>::resolve(), curr->arg(Index).info()) && ...)) {
+            if(curr->arity == sizeof...(Args) && (can_cast_or_convert(internal::meta_info<Args>::resolve(), curr->arg(Index).info()) && ...)) {
                 return curr;
             }
         }
@@ -1178,7 +1178,7 @@ public:
      * @return The number of template arguments, if any.
      */
     [[nodiscard]] size_type template_arity() const ENTT_NOEXCEPT {
-        return node->template_info.template_arity;
+        return node->template_info.arity;
     }
 
     /**
@@ -1189,7 +1189,7 @@ public:
      * @return The tag for the class template of the underlying type.
      */
     [[nodiscard]] inline meta_type template_type() const ENTT_NOEXCEPT {
-        return is_template_specialization() ?  node->template_info.template_type() : meta_type{};
+        return is_template_specialization() ?  node->template_info.type() : meta_type{};
     }
 
     /**
@@ -1198,7 +1198,7 @@ public:
      * @return The type of the i-th template argument of a type.
      */
     [[nodiscard]] inline meta_type template_arg(size_type index) const ENTT_NOEXCEPT {
-        return index < template_arity() ? node->template_info.template_arg(index) : meta_type{};
+        return index < template_arity() ? node->template_info.arg(index) : meta_type{};
     }
 
     /**
@@ -1326,7 +1326,7 @@ public:
      */
     [[nodiscard]] meta_any construct(meta_any * const args, const size_type sz) const {
         meta_any any{};
-        internal::meta_visit<&node_type::ctor>([args, sz, &any](const auto *curr) { return (curr->size == sz) && (any = curr->invoke(args)); }, node);
+        internal::meta_visit<&node_type::ctor>([args, sz, &any](const auto *curr) { return (curr->arity == sz) && (any = curr->invoke(args)); }, node);
         return any;
     }
 
@@ -1365,7 +1365,7 @@ public:
         size_type extent{sz + 1u};
         bool ambiguous{};
 
-        for(auto *it = internal::meta_visit<&node_type::func>([id, sz](const auto *curr) { return curr->id == id && curr->size == sz; }, node); it && it->id == id && it->size == sz; it = it->next) {
+        for(auto *it = internal::meta_visit<&node_type::func>([id, sz](const auto *curr) { return curr->id == id && curr->arity == sz; }, node); it && it->id == id && it->arity == sz; it = it->next) {
             size_type direct{};
             size_type ext{};
 
@@ -1578,7 +1578,7 @@ bool meta_any::set(const id_type id, Type &&value) {
 
 
 [[nodiscard]] inline meta_type meta_ctor::arg(size_type index) const ENTT_NOEXCEPT {
-    return index < size() ? node->arg(index) : meta_type{};
+    return index < arity() ? node->arg(index) : meta_type{};
 }
 
 
@@ -1603,7 +1603,7 @@ bool meta_any::set(const id_type id, Type &&value) {
 
 
 [[nodiscard]] inline meta_type meta_func::arg(size_type index) const ENTT_NOEXCEPT {
-    return index < size() ? node->arg(index) : meta_type{};
+    return index < arity() ? node->arg(index) : meta_type{};
 }
 
 

+ 5 - 5
src/entt/meta/node.hpp

@@ -68,7 +68,7 @@ struct meta_ctor_node {
     meta_type_node * const parent;
     meta_ctor_node * next;
     meta_prop_node * prop;
-    const size_type size;
+    const size_type arity;
     meta_type(* const arg)(const size_type) ENTT_NOEXCEPT;
     meta_any(* const invoke)(meta_any * const);
 };
@@ -93,7 +93,7 @@ struct meta_func_node {
     meta_type_node * const parent;
     meta_func_node * next;
     meta_prop_node * prop;
-    const size_type size;
+    const size_type arity;
     const bool is_const;
     const bool is_static;
     meta_type_node *(* const ret)() ENTT_NOEXCEPT;
@@ -105,9 +105,9 @@ struct meta_func_node {
 struct meta_template_info {
     using size_type = std::size_t;
     const bool is_template_specialization;
-    const size_type template_arity;
-    meta_type_node *(* const template_type)() ENTT_NOEXCEPT;
-    meta_type_node *(* const template_arg)(const size_type) ENTT_NOEXCEPT;
+    const size_type arity;
+    meta_type_node *(* const type)() ENTT_NOEXCEPT;
+    meta_type_node *(* const arg)(const size_type) ENTT_NOEXCEPT;
 };
 
 

+ 4 - 4
test/entt/meta/meta_ctor.cpp

@@ -55,7 +55,7 @@ TEST_F(MetaCtor, Functionalities) {
 
     ASSERT_TRUE(ctor);
     ASSERT_EQ(ctor.parent(), entt::resolve("clazz"_hs));
-    ASSERT_EQ(ctor.size(), 2u);
+    ASSERT_EQ(ctor.arity(), 2u);
     ASSERT_EQ(ctor.arg(0u), entt::resolve<int>());
     ASSERT_EQ(ctor.arg(1u), entt::resolve<char>());
     ASSERT_FALSE(ctor.arg(2u));
@@ -90,7 +90,7 @@ TEST_F(MetaCtor, Func) {
 
     ASSERT_TRUE(ctor);
     ASSERT_EQ(ctor.parent(), entt::resolve("clazz"_hs));
-    ASSERT_EQ(ctor.size(), 1u);
+    ASSERT_EQ(ctor.arity(), 1u);
     ASSERT_EQ(ctor.arg(0u), entt::resolve<int>());
     ASSERT_FALSE(ctor.arg(1u));
 
@@ -190,7 +190,7 @@ TEST_F(MetaCtor, ExternalMemberFunction) {
 
     ASSERT_TRUE(ctor);
     ASSERT_EQ(ctor.parent(), entt::resolve("clazz"_hs));
-    ASSERT_EQ(ctor.size(), 4u);
+    ASSERT_EQ(ctor.arity(), 4u);
     ASSERT_EQ(ctor.arg(0u), entt::resolve<entt::registry>());
     ASSERT_EQ(ctor.arg(1u), entt::resolve<entt::entity>());
     ASSERT_EQ(ctor.arg(2u), entt::resolve<int>());
@@ -221,7 +221,7 @@ TEST_F(MetaCtor, ImplicitlyGeneratedDefaultConstructor) {
     // default constructor is implicitly generated
     ASSERT_EQ(counter, 1);
     ASSERT_TRUE(type.ctor<>());
-    ASSERT_EQ(type.ctor<>().size(), 0u);
+    ASSERT_EQ(type.ctor<>().arity(), 0u);
     ASSERT_EQ(type.ctor<>().arg(0), entt::meta_type{});
 
     auto any = type.ctor<>().invoke();

+ 6 - 6
test/entt/meta/meta_func.cpp

@@ -94,7 +94,7 @@ TEST_F(MetaFunc, Functionalities) {
     ASSERT_TRUE(func);
     ASSERT_EQ(func.parent(), entt::resolve("func"_hs));
     ASSERT_EQ(func.id(), "f2"_hs);
-    ASSERT_EQ(func.size(), 2u);
+    ASSERT_EQ(func.arity(), 2u);
     ASSERT_FALSE(func.is_const());
     ASSERT_FALSE(func.is_static());
     ASSERT_EQ(func.ret(), entt::resolve<int>());
@@ -135,7 +135,7 @@ TEST_F(MetaFunc, Const) {
     ASSERT_TRUE(func);
     ASSERT_EQ(func.parent(), entt::resolve("func"_hs));
     ASSERT_EQ(func.id(), "f1"_hs);
-    ASSERT_EQ(func.size(), 1u);
+    ASSERT_EQ(func.arity(), 1u);
     ASSERT_TRUE(func.is_const());
     ASSERT_FALSE(func.is_static());
     ASSERT_EQ(func.ret(), entt::resolve<int>());
@@ -174,7 +174,7 @@ TEST_F(MetaFunc, RetVoid) {
     ASSERT_TRUE(func);
     ASSERT_EQ(func.parent(), entt::resolve("func"_hs));
     ASSERT_EQ(func.id(), "g"_hs);
-    ASSERT_EQ(func.size(), 1u);
+    ASSERT_EQ(func.arity(), 1u);
     ASSERT_FALSE(func.is_const());
     ASSERT_FALSE(func.is_static());
     ASSERT_EQ(func.ret(), entt::resolve<void>());
@@ -211,7 +211,7 @@ TEST_F(MetaFunc, Static) {
     ASSERT_TRUE(func);
     ASSERT_EQ(func.parent(), entt::resolve("func"_hs));
     ASSERT_EQ(func.id(), "h"_hs);
-    ASSERT_EQ(func.size(), 1u);
+    ASSERT_EQ(func.arity(), 1u);
     ASSERT_FALSE(func.is_const());
     ASSERT_TRUE(func.is_static());
     ASSERT_EQ(func.ret(), entt::resolve<int>());
@@ -249,7 +249,7 @@ TEST_F(MetaFunc, StaticRetVoid) {
     ASSERT_TRUE(func);
     ASSERT_EQ(func.parent(), entt::resolve("func"_hs));
     ASSERT_EQ(func.id(), "k"_hs);
-    ASSERT_EQ(func.size(), 1u);
+    ASSERT_EQ(func.arity(), 1u);
     ASSERT_FALSE(func.is_const());
     ASSERT_TRUE(func.is_static());
     ASSERT_EQ(func.ret(), entt::resolve<void>());
@@ -404,7 +404,7 @@ TEST_F(MetaFunc, ExternalMemberFunction) {
     ASSERT_TRUE(func);
     ASSERT_EQ(func.parent(), entt::resolve("func"_hs));
     ASSERT_EQ(func.id(), "emplace"_hs);
-    ASSERT_EQ(func.size(), 2u);
+    ASSERT_EQ(func.arity(), 2u);
     ASSERT_FALSE(func.is_const());
     ASSERT_TRUE(func.is_static());
     ASSERT_EQ(func.ret(), entt::resolve<void>());