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

entity: avoid cost of requires and guard the most used functions

skypjack 1 месяц назад
Родитель
Сommit
7d73129f38
1 измененных файлов с 2 добавлено и 1 удалено
  1. 2 1
      src/entt/entity/entity.hpp

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

@@ -73,7 +73,6 @@ concept entity_like = requires {
  * @tparam Traits Actual entity traits to use.
  */
 template<typename Traits>
-requires ((Traits::entity_mask & (Traits::entity_mask + 1)) == 0) && ((Traits::version_mask & (Traits::version_mask + 1)) == 0)
 class basic_entt_traits {
     static constexpr auto length = stl::popcount(Traits::entity_mask);
 
@@ -105,6 +104,7 @@ public:
      * @return The integral representation of the entity part.
      */
     [[nodiscard]] static constexpr entity_type to_entity(const value_type value) noexcept {
+        static_assert(Traits::entity_mask && ((Traits::entity_mask & (Traits::entity_mask + 1)) == 0), "Invalid entity mask");
         return (to_integral(value) & entity_mask);
     }
 
@@ -117,6 +117,7 @@ public:
         if constexpr(Traits::version_mask == 0u) {
             return version_type{};
         } else {
+            static_assert((Traits::version_mask & (Traits::version_mask + 1)) == 0, "Invalid version mask");
             return (static_cast<version_type>(to_integral(value) >> length) & version_mask);
         }
     }