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

type_id: reduce the number of static variables due to type_id

Michele Caini 4 лет назад
Родитель
Сommit
0fa586a3d8
1 измененных файлов с 6 добавлено и 2 удалено
  1. 6 2
      src/entt/core/type_info.hpp

+ 6 - 2
src/entt/core/type_info.hpp

@@ -254,8 +254,12 @@ private:
  */
 template<typename Type>
 [[nodiscard]] const type_info &type_id() ENTT_NOEXCEPT {
-    static type_info instance{std::in_place_type<std::remove_cv_t<std::remove_reference_t<Type>>>};
-    return instance;
+    if constexpr(std::is_same_v<Type, std::remove_cv_t<std::remove_reference_t<Type>>>) {
+        static type_info instance{std::in_place_type<std::remove_cv_t<std::remove_reference_t<Type>>>};
+        return instance;
+    } else {
+        return type_id<std::remove_cv_t<std::remove_reference_t<Type>>>();
+    }
 }
 
 } // namespace entt