Quellcode durchsuchen

config: renamed ENTT_ENABLE_ETO to ENTT_IS_EMPTY

Michele Caini vor 6 Jahren
Ursprung
Commit
e69d1556e1

+ 0 - 1
TODO

@@ -19,7 +19,6 @@
 Next:
 * replace observer class with observer functions
 * get(cmp, entity) -> void *, set(cmp, entity, void *)
-* ENTT_ENABLE_ETO -> ENTT_IS_EMPTY (ignore default constructible)
 * review multi component views to reduce instantiations once empty types are gone...
 * avoid using deprecated functions all around
 * accept fixed type iterators like std::container<T> does rather than all possible types

+ 1 - 1
docs/md/entity.md

@@ -721,7 +721,7 @@ A general purpose cloning function could be defined as:
 ```cpp
 template<typename Type>
 void clone(const entt::registry &from, entt::registry &to) {
-    if constexpr(ENTT_ENABLE_ETO(Type)) {
+    if constexpr(ENTT_IS_EMPTY(Type)) {
         to.insert<Type>(from.data<Type>(), from.data<Type>() + from.size<Type>());
     } else {
         to.insert<Type>(from.data<Type>(), from.data<Type>() + from.size<Type>(), from.raw<Type>());

+ 2 - 2
src/entt/config/config.h

@@ -44,10 +44,10 @@
 
 #ifndef ENTT_DISABLE_ETO
 #   include <type_traits>
-#   define ENTT_ENABLE_ETO(Type) (std::is_default_constructible_v<Type> && std::is_empty_v<Type>)
+#   define ENTT_IS_EMPTY(Type) std::is_empty_v<Type>
 #else
 #   // sfinae-friendly definition
-#   define ENTT_ENABLE_ETO(Type) (false && std::is_void_v<Type>)
+#   define ENTT_IS_EMPTY(Type) decltype(Type, bool{}){}
 #endif
 
 

+ 3 - 3
src/entt/entity/group.hpp

@@ -334,7 +334,7 @@ public:
      */
     template<typename Func>
     void each(Func func) const {
-        using get_type_list = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Get), type_list<>, type_list<Get>>...>;
+        using get_type_list = type_list_cat_t<std::conditional_t<ENTT_IS_EMPTY(Get), type_list<>, type_list<Get>>...>;
         traverse(std::move(func), get_type_list{});
     }
 
@@ -772,8 +772,8 @@ public:
      */
     template<typename Func>
     void each(Func func) const {
-        using owned_type_list = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Owned), type_list<>, type_list<Owned>>...>;
-        using get_type_list = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Get), type_list<>, type_list<Get>>...>;
+        using owned_type_list = type_list_cat_t<std::conditional_t<ENTT_IS_EMPTY(Owned), type_list<>, type_list<Owned>>...>;
+        using get_type_list = type_list_cat_t<std::conditional_t<ENTT_IS_EMPTY(Get), type_list<>, type_list<Get>>...>;
         traverse(std::move(func), owned_type_list{}, get_type_list{});
     }
 

+ 3 - 3
src/entt/entity/registry.hpp

@@ -66,7 +66,7 @@ class basic_registry {
             this->construct(entt, std::forward<Args>(args)...);
             construction.publish(owner, entt);
 
-            if constexpr(!ENTT_ENABLE_ETO(Component)) {
+            if constexpr(!ENTT_IS_EMPTY(Component)) {
                 return this->get(entt);
             }
         }
@@ -103,13 +103,13 @@ class basic_registry {
             (std::forward<Func>(func)(this->get(entt)), ...);
             update.publish(owner, entt);
 
-            if constexpr(!ENTT_ENABLE_ETO(Component)) {
+            if constexpr(!ENTT_IS_EMPTY(Component)) {
                 return this->get(entt);
             }
         }
 
         decltype(auto) replace(basic_registry &owner, const Entity entt, [[maybe_unused]] Component component) {
-            if constexpr(ENTT_ENABLE_ETO(Component)) {
+            if constexpr(ENTT_IS_EMPTY(Component)) {
                 return patch(owner, entt);
             } else {
                 return patch(owner, entt, [&component](auto &&curr) { curr = std::move(component); });

+ 1 - 1
src/entt/entity/storage.hpp

@@ -505,7 +505,7 @@ private:
 
 /*! @copydoc storage */
 template<typename Entity, typename Type>
-class storage<Entity, Type, std::enable_if_t<ENTT_ENABLE_ETO(Type)>>: public sparse_set<Entity> {
+class storage<Entity, Type, std::enable_if_t<ENTT_IS_EMPTY(Type)>>: public sparse_set<Entity> {
     using traits_type = entt_traits<std::underlying_type_t<Entity>>;
     using underlying_type = sparse_set<Entity>;
 

+ 2 - 2
src/entt/entity/view.hpp

@@ -452,7 +452,7 @@ public:
      */
     template<typename Comp, typename Func>
     void each(Func func) const {
-        using non_empty_type = type_list_cat_t<std::conditional_t<ENTT_ENABLE_ETO(Component), type_list<>, type_list<Component>>...>;
+        using non_empty_type = type_list_cat_t<std::conditional_t<ENTT_IS_EMPTY(Component), type_list<>, type_list<Component>>...>;
         traverse<Comp>(std::move(func), non_empty_type{});
     }
 
@@ -743,7 +743,7 @@ public:
      */
     template<typename Func>
     void each(Func func) const {
-        if constexpr(ENTT_ENABLE_ETO(Component)) {
+        if constexpr(ENTT_IS_EMPTY(Component)) {
             if constexpr(std::is_invocable_v<Func>) {
                 for(auto pos = pool->size(); pos; --pos) {
                     func();