Ver Fonte

linter: I prefer my previous approach :) to coding style

Michele Caini há 1 ano atrás
pai
commit
7ce821f92e
4 ficheiros alterados com 32 adições e 31 exclusões
  1. 1 0
      .clang-tidy
  2. 16 15
      src/entt/core/any.hpp
  3. 9 12
      src/entt/entity/sparse_set.hpp
  4. 6 4
      src/entt/graph/adjacency_matrix.hpp

+ 1 - 0
.clang-tidy

@@ -4,6 +4,7 @@ Checks: >
     cppcoreguidelines-*,
     -cppcoreguidelines-owning-memory,
     -cppcoreguidelines-pro-type-const-cast,
+    -cppcoreguidelines-pro-type-member-init,
     -cppcoreguidelines-pro-type-reinterpret-cast,
     -cppcoreguidelines-pro-type-union-access,
     misc-*,

+ 16 - 15
src/entt/core/any.hpp

@@ -145,8 +145,8 @@ class basic_any {
     basic_any(const basic_any &other, const any_policy pol) noexcept
         : instance{other.data()},
           info{other.info},
-          mode{pol},
-          vtable{other.vtable} {}
+          vtable{other.vtable},
+          mode{pol} {}
 
 public:
     /*! @brief Size of the internal storage. */
@@ -156,7 +156,7 @@ public:
 
     /*! @brief Default constructor. */
     constexpr basic_any() noexcept
-        : instance{} {}
+        : basic_any{std::in_place_type<void>} {}
 
     /**
      * @brief Constructs a wrapper by directly initializing the new object.
@@ -166,7 +166,10 @@ public:
      */
     template<typename Type, typename... Args>
     explicit basic_any(std::in_place_type_t<Type>, Args &&...args)
-        : instance{} {
+        : instance{},
+          info{},
+          vtable{},
+          mode{any_policy::owner} {
         initialize<Type>(std::forward<Args>(args)...);
     }
 
@@ -177,16 +180,14 @@ public:
      */
     template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::decay_t<Type>, basic_any>>>
     basic_any(Type &&value)
-        : instance{} {
-        initialize<std::decay_t<Type>>(std::forward<Type>(value));
-    }
+        : basic_any{std::in_place_type<std::decay_t<Type>>, std::forward<Type>(value)} {}
 
     /**
      * @brief Copy constructor.
      * @param other The instance to copy from.
      */
     basic_any(const basic_any &other)
-        : instance{} {
+        : basic_any{} {
         if(other.vtable) {
             other.vtable(operation::copy, other, this);
         }
@@ -199,8 +200,8 @@ public:
     basic_any(basic_any &&other) noexcept
         : instance{},
           info{other.info},
-          mode{other.mode},
-          vtable{other.vtable} {
+          vtable{other.vtable},
+          mode{other.mode} {
         if(other.vtable) {
             other.vtable(operation::move, other, this);
         }
@@ -239,8 +240,8 @@ public:
         if(other.vtable) {
             other.vtable(operation::move, other, this);
             info = other.info;
-            mode = other.mode;
             vtable = other.vtable;
+            mode = other.mode;
         }
 
         return *this;
@@ -347,8 +348,8 @@ public:
         // unnecessary but it helps to detect nasty bugs
         ENTT_ASSERT((instance = nullptr) == nullptr, "");
         info = &type_id<void>();
-        mode = any_policy::owner;
         vtable = nullptr;
+        mode = any_policy::owner;
     }
 
     /**
@@ -407,9 +408,9 @@ private:
         const void *instance;
         storage_type storage;
     };
-    const type_info *info{&type_id<void>()};
-    any_policy mode{any_policy::owner};
-    vtable_type *vtable{};
+    const type_info *info;
+    vtable_type *vtable;
+    any_policy mode;
 };
 
 /**

+ 9 - 12
src/entt/entity/sparse_set.hpp

@@ -391,15 +391,15 @@ public:
     using const_reverse_iterator = std::reverse_iterator<const_iterator>;
 
     /*! @brief Default constructor. */
-    basic_sparse_set() = default;
+    basic_sparse_set()
+        : basic_sparse_set{type_id<void>()} {}
 
     /**
      * @brief Constructs an empty container with a given allocator.
      * @param allocator The allocator to use.
      */
     explicit basic_sparse_set(const allocator_type &allocator)
-        : sparse{allocator},
-          packed{allocator} {}
+        : basic_sparse_set{deletion_policy::swap_and_pop, allocator} {}
 
     /**
      * @brief Constructs an empty container with the given policy and allocator.
@@ -407,10 +407,7 @@ public:
      * @param allocator The allocator to use (possibly default-constructed).
      */
     explicit basic_sparse_set(deletion_policy pol, const allocator_type &allocator = {})
-        : sparse{allocator},
-          packed{allocator},
-          mode{pol},
-          head{policy_to_head()} {}
+        : basic_sparse_set{type_id<void>(), pol, allocator} {}
 
     /**
      * @brief Constructs an empty container with the given value type, policy
@@ -1060,11 +1057,11 @@ public:
     virtual void bind(any) noexcept {}
 
 private:
-    sparse_container_type sparse{};
-    packed_container_type packed{};
-    const type_info *info{&type_id<void>()};
-    deletion_policy mode{deletion_policy::swap_and_pop};
-    size_type head{max_size};
+    sparse_container_type sparse;
+    packed_container_type packed;
+    const type_info *info;
+    deletion_policy mode;
+    size_type head;
 };
 
 } // namespace entt

+ 6 - 4
src/entt/graph/adjacency_matrix.hpp

@@ -114,14 +114,16 @@ public:
     using graph_category = Category;
 
     /*! @brief Default constructor. */
-    adjacency_matrix() noexcept(noexcept(allocator_type{})) = default;
+    adjacency_matrix() noexcept(noexcept(allocator_type{}))
+        : adjacency_matrix{0u} {
+    }
 
     /**
      * @brief Constructs an empty container with a given allocator.
      * @param allocator The allocator to use.
      */
     explicit adjacency_matrix(const allocator_type &allocator) noexcept
-        : matrix{allocator} {}
+        : adjacency_matrix{0u, allocator} {}
 
     /**
      * @brief Constructs an empty container with a given allocator and user
@@ -324,8 +326,8 @@ public:
     }
 
 private:
-    container_type matrix{};
-    size_type vert{};
+    container_type matrix;
+    size_type vert;
 };
 
 } // namespace entt