component: reintroduce utility ignore_as_empty_v (it's actually useful sometimes)

This commit is contained in:
Michele Caini
2022-03-15 10:43:37 +01:00
parent 805bb84c8f
commit e13d06fe20
3 changed files with 12 additions and 1 deletions

View File

@@ -49,6 +49,13 @@ struct component_traits {
static constexpr std::size_t page_size = internal::page_size<Type>::value;
};
/**
* @brief Helper variable template.
* @tparam Type Type of component.
*/
template<class Type>
inline constexpr bool ignore_as_empty_v = (component_traits<Type>::page_size == 0u);
} // namespace entt
#endif

View File

@@ -743,7 +743,7 @@ private:
/*! @copydoc basic_storage */
template<typename Entity, typename Type, typename Allocator>
class basic_storage<Entity, Type, Allocator, std::enable_if_t<component_traits<Type>::page_size == 0u>>
class basic_storage<Entity, Type, Allocator, std::enable_if_t<ignore_as_empty_v<Type>>>
: public basic_sparse_set<Entity, typename std::allocator_traits<Allocator>::template rebind_alloc<Entity>> {
using alloc_traits = std::allocator_traits<Allocator>;
static_assert(std::is_same_v<typename alloc_traits::value_type, Type>);

View File

@@ -24,6 +24,7 @@ TEST(Component, DefaultParamsEmpty) {
static_assert(!traits::in_place_delete);
static_assert(traits::page_size == 0u);
static_assert(entt::ignore_as_empty_v<default_params_empty>);
}
TEST(Component, DefaultParamsNonEmpty) {
@@ -31,6 +32,7 @@ TEST(Component, DefaultParamsNonEmpty) {
static_assert(!traits::in_place_delete);
static_assert(traits::page_size == ENTT_PACKED_PAGE);
static_assert(!entt::ignore_as_empty_v<default_params_non_empty>);
}
TEST(Component, SelfContained) {
@@ -38,6 +40,7 @@ TEST(Component, SelfContained) {
static_assert(traits::in_place_delete);
static_assert(traits::page_size == 4u);
static_assert(!entt::ignore_as_empty_v<self_contained>);
}
TEST(Component, TraitsBased) {
@@ -45,4 +48,5 @@ TEST(Component, TraitsBased) {
static_assert(!traits::in_place_delete);
static_assert(traits::page_size == 8u);
static_assert(!entt::ignore_as_empty_v<traits_based>);
}