traits: is_eto_eligible[_v] -> is_empty[_v], internal version

This commit is contained in:
Michele Caini
2020-10-28 22:58:26 +01:00
parent 09da190e93
commit 4ad411e320
5 changed files with 23 additions and 25 deletions

View File

@@ -309,7 +309,7 @@ inline constexpr auto is_applicable_r_v = is_applicable_r<Ret, Func, Args>::valu
* @tparam Type Potential empty type.
*/
template<typename Type, typename = void>
struct is_eto_eligible
struct is_empty
: ENTT_IS_EMPTY(Type)
{};
@@ -319,7 +319,7 @@ struct is_eto_eligible
* @tparam Type Potential empty type.
*/
template<typename Type>
inline constexpr auto is_eto_eligible_v = is_eto_eligible<Type>::value;
inline constexpr auto is_empty_v = is_empty<Type>::value;
/**

View File

@@ -129,11 +129,11 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> final {
public:
using iterator = iterable_group_iterator<
typename basic_sparse_set<Entity>::iterator,
type_list_cat_t<std::conditional_t<is_eto_eligible_v<Get>, type_list<>, type_list<Get>>...>
type_list_cat_t<std::conditional_t<is_empty_v<Get>, type_list<>, type_list<Get>>...>
>;
using reverse_iterator = iterable_group_iterator<
typename basic_sparse_set<Entity>::reverse_iterator,
type_list_cat_t<std::conditional_t<is_eto_eligible_v<Get>, type_list<>, type_list<Get>>...>
type_list_cat_t<std::conditional_t<is_empty_v<Get>, type_list<>, type_list<Get>>...>
>;
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
@@ -408,7 +408,7 @@ public:
if constexpr(sizeof...(Component) == 0) {
return std::tuple_cat([entt](auto *cpool) {
if constexpr(is_eto_eligible_v<typename std::remove_reference_t<decltype(*cpool)>::value_type>) {
if constexpr(is_empty_v<typename std::remove_reference_t<decltype(*cpool)>::value_type>) {
return std::tuple{};
} else {
return std::forward_as_tuple(cpool->get(entt));
@@ -445,7 +445,7 @@ public:
*/
template<typename Func>
void each(Func func) const {
traverse(std::move(func), (std::conditional_t<is_eto_eligible_v<Get>, type_list<>, type_list<Get>>{} + ...));
traverse(std::move(func), (std::conditional_t<is_empty_v<Get>, type_list<>, type_list<Get>>{} + ...));
}
/**
@@ -661,13 +661,13 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> final
public:
using iterator = iterable_group_iterator<
typename basic_sparse_set<Entity>::iterator,
type_list_cat_t<std::conditional_t<is_eto_eligible_v<Owned>, type_list<>, type_list<decltype(std::declval<pool_type<Owned>>().end())>>...>,
type_list_cat_t<std::conditional_t<is_eto_eligible_v<Get>, type_list<>, type_list<Get>>...>
type_list_cat_t<std::conditional_t<is_empty_v<Owned>, type_list<>, type_list<decltype(std::declval<pool_type<Owned>>().end())>>...>,
type_list_cat_t<std::conditional_t<is_empty_v<Get>, type_list<>, type_list<Get>>...>
>;
using reverse_iterator = iterable_group_iterator<
typename basic_sparse_set<Entity>::reverse_iterator,
type_list_cat_t<std::conditional_t<is_eto_eligible_v<Owned>, type_list<>, type_list<decltype(std::declval<pool_type<Owned>>().rbegin())>>...>,
type_list_cat_t<std::conditional_t<is_eto_eligible_v<Get>, type_list<>, type_list<Get>>...>
type_list_cat_t<std::conditional_t<is_empty_v<Owned>, type_list<>, type_list<decltype(std::declval<pool_type<Owned>>().rbegin())>>...>,
type_list_cat_t<std::conditional_t<is_empty_v<Get>, type_list<>, type_list<Get>>...>
>;
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
@@ -957,7 +957,7 @@ public:
auto filter = [entt, index = std::get<0>(pools)->index(entt)](auto *cpool) {
using value_type = typename std::remove_reference_t<decltype(*cpool)>::value_type;
if constexpr(is_eto_eligible_v<value_type>) {
if constexpr(is_empty_v<value_type>) {
return std::tuple{};
} else if constexpr((std::is_same_v<value_type, std::remove_const_t<Owned>> || ...)) {
return std::forward_as_tuple(cpool->raw()[index]);
@@ -999,8 +999,8 @@ public:
template<typename Func>
void each(Func func) const {
traverse(std::move(func),
(std::conditional_t<is_eto_eligible_v<Owned>, type_list<>, type_list<Owned>>{} + ...),
(type_list<>{} + ... + std::conditional_t<is_eto_eligible_v<Get>, type_list<>, type_list<Get>>{}));
(std::conditional_t<is_empty_v<Owned>, type_list<>, type_list<Owned>>{} + ...),
(type_list<>{} + ... + std::conditional_t<is_empty_v<Get>, type_list<>, type_list<Get>>{}));
}
/**

View File

@@ -179,7 +179,7 @@ struct sigh_pool_mixin: Pool {
Pool::emplace(owner, entity, std::forward<Args>(args)...);
construction.publish(owner, entity);
if constexpr(!is_eto_eligible_v<value_type>) {
if constexpr(!is_empty_v<value_type>) {
return this->get(entity);
}
}
@@ -244,7 +244,7 @@ struct sigh_pool_mixin: Pool {
*/
template<typename... Func>
decltype(auto) patch(basic_registry<entity_type> &owner, const entity_type entity, [[maybe_unused]] Func &&... func) {
if constexpr(is_eto_eligible_v<value_type>) {
if constexpr(is_empty_v<value_type>) {
update.publish(owner, entity);
} else {
Pool::patch(owner, entity, std::forward<Func>(func)...);

View File

@@ -535,7 +535,7 @@ private:
/*! @copydoc basic_storage */
template<typename Entity, typename Type>
class basic_storage<Entity, Type, std::enable_if_t<is_eto_eligible_v<Type>>>: public basic_sparse_set<Entity> {
class basic_storage<Entity, Type, std::enable_if_t<is_empty_v<Type>>>: public basic_sparse_set<Entity> {
using underlying_type = basic_sparse_set<Entity>;
public:

View File

@@ -71,7 +71,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
template<typename Comp>
using pool_type = pool_t<Entity, Comp>;
using return_type = type_list_cat_t<std::conditional_t<is_eto_eligible_v<Component>, type_list<>, type_list<Component>>...>;
using return_type = type_list_cat_t<std::conditional_t<is_empty_v<Component>, type_list<>, type_list<Component>>...>;
using unchecked_type = std::array<const basic_sparse_set<Entity> *, (sizeof...(Component) - 1)>;
template<typename It>
@@ -290,9 +290,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
auto first = view->data();
while(first != last) {
if((std::get<pool_type<Component> *>(pools)->contains(*first) && ...)
&& !(std::get<const pool_type<Exclude> *>(filter)->contains(*first) || ...))
{
if((std::get<pool_type<Component> *>(pools)->contains(*first) && ...) && !(std::get<const pool_type<Exclude> *>(filter)->contains(*first) || ...)) {
const auto base = *(first++);
const auto chunk = (std::min)({ (std::get<pool_type<Component> *>(pools)->size() - std::get<pool_type<Component> *>(pools)->index(base))... });
size_type length{};
@@ -443,7 +441,7 @@ public:
if constexpr(sizeof...(Comp) == 0) {
return std::tuple_cat([entt](auto *cpool) {
if constexpr(is_eto_eligible_v<typename std::remove_reference_t<decltype(*cpool)>::value_type>) {
if constexpr(is_empty_v<typename std::remove_reference_t<decltype(*cpool)>::value_type>) {
return std::tuple{};
} else {
return std::forward_as_tuple(cpool->get(entt));
@@ -674,12 +672,12 @@ class basic_view<Entity, exclude_t<>, Component> final {
public:
using iterator = std::conditional_t<
is_eto_eligible_v<Component>,
is_empty_v<Component>,
iterable_view_iterator<typename basic_sparse_set<Entity>::iterator>,
iterable_view_iterator<typename basic_sparse_set<Entity>::iterator, decltype(std::declval<pool_type>().begin())>
>;
using reverse_iterator = std::conditional_t<
is_eto_eligible_v<Component>,
is_empty_v<Component>,
iterable_view_iterator<typename basic_sparse_set<Entity>::reverse_iterator>,
iterable_view_iterator<typename basic_sparse_set<Entity>::reverse_iterator, decltype(std::declval<pool_type>().rbegin())>
>;
@@ -889,7 +887,7 @@ public:
template<typename... Comp>
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
if constexpr(sizeof...(Comp) == 0) {
if constexpr(is_eto_eligible_v<Component>) {
if constexpr(is_empty_v<Component>) {
return std::tuple{};
} else {
return std::forward_as_tuple(pool->get(entt));
@@ -924,7 +922,7 @@ public:
*/
template<typename Func>
void each(Func func) const {
if constexpr(is_eto_eligible_v<Component>) {
if constexpr(is_empty_v<Component>) {
if constexpr(std::is_invocable_v<Func, entity_type>) {
for(const auto entt: *this) {
func(entt);