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

core/entity: spot and remove useless add_const_t

Michele Caini 3 лет назад
Родитель
Сommit
8c23f2de8b

+ 0 - 1
TODO

@@ -11,7 +11,6 @@ DOC:
 * examples (and credits) from @alanjfs :)
 
 WIP:
-* spot and remove useless add_const_t
 * add storage getter for filters to views and groups
 * no () = default ctor for iterators with uninitialized members
 * remove storage::base_type, make views extract the sparse set directly

+ 1 - 1
src/entt/core/type_traits.hpp

@@ -606,7 +606,7 @@ struct constness_as {
 template<typename To, typename From>
 struct constness_as<To, const From> {
     /*! @brief The type resulting from the transcription of the constness. */
-    using type = std::add_const_t<To>;
+    using type = const To;
 };
 
 /**

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

@@ -34,12 +34,12 @@ inline constexpr bool is_view_v = is_view<Type>::value;
 template<typename Type, typename Override>
 struct unpack_type {
     using ro = std::conditional_t<
-        type_list_contains_v<Override, std::add_const_t<Type>> || (std::is_const_v<Type> && !type_list_contains_v<Override, std::remove_const_t<Type>>),
+        type_list_contains_v<Override, const Type> || (std::is_const_v<Type> && !type_list_contains_v<Override, std::remove_const_t<Type>>),
         type_list<std::remove_const_t<Type>>,
         type_list<>>;
 
     using rw = std::conditional_t<
-        type_list_contains_v<Override, std::remove_const_t<Type>> || (!std::is_const_v<Type> && !type_list_contains_v<Override, std::add_const_t<Type>>),
+        type_list_contains_v<Override, std::remove_const_t<Type>> || (!std::is_const_v<Type> && !type_list_contains_v<Override, const Type>),
         type_list<Type>,
         type_list<>>;
 };

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

@@ -174,8 +174,8 @@ struct registry_context {
     }
 
     template<typename Type>
-    [[nodiscard]] std::add_const_t<Type> &at(const id_type id = type_id<Type>().hash()) const {
-        return any_cast<std::add_const_t<Type> &>(data.at(id));
+    [[nodiscard]] const Type &at(const id_type id = type_id<Type>().hash()) const {
+        return any_cast<const Type &>(data.at(id));
     }
 
     template<typename Type>
@@ -184,9 +184,9 @@ struct registry_context {
     }
 
     template<typename Type>
-    [[nodiscard]] std::add_const_t<Type> *find(const id_type id = type_id<Type>().hash()) const {
+    [[nodiscard]] const Type *find(const id_type id = type_id<Type>().hash()) const {
         const auto it = data.find(id);
-        return it != data.cend() ? any_cast<std::add_const_t<Type>>(&it->second) : nullptr;
+        return it != data.cend() ? any_cast<const Type>(&it->second) : nullptr;
     }
 
     template<typename Type>

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

@@ -34,7 +34,7 @@ class basic_snapshot {
 
     template<typename Component, typename Archive, typename It>
     void get(Archive &archive, std::size_t sz, It first, It last) const {
-        const auto view = reg->template view<std::add_const_t<Component>>();
+        const auto view = reg->template view<const Component>();
         archive(typename entity_traits::entity_type(sz));
 
         while(first != last) {