core/entity: spot and remove useless add_const_t

This commit is contained in:
Michele Caini
2022-04-29 12:24:47 +02:00
parent 837481a854
commit 8c23f2de8b
5 changed files with 8 additions and 9 deletions

1
TODO
View File

@@ -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

View File

@@ -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;
};
/**

View File

@@ -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<>>;
};

View File

@@ -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>

View File

@@ -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) {