From 85c0c56e0300a3b1f05b3f2f20cb02b6e4a2860d Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sat, 26 Aug 2023 22:11:55 +0300 Subject: [PATCH] Add static asserts in ecs::entity_component::apply/batch_apply to check that all component types are different --- libs/ecs/include/psemek/ecs/entity_container.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/ecs/include/psemek/ecs/entity_container.hpp b/libs/ecs/include/psemek/ecs/entity_container.hpp index c7f76bf3..f23153a5 100644 --- a/libs/ecs/include/psemek/ecs/entity_container.hpp +++ b/libs/ecs/include/psemek/ecs/entity_container.hpp @@ -107,6 +107,8 @@ namespace psemek::ecs * The function is guaranteed not to visit destroyed entities (unless it did * so before the entity was destroyed). * An optional query cache can be supplied to speed up iteration. + * If any two of the passed component types are equal, the call fails with + * a compilation error. * If the query cache wasn't created with the exact sequence of component * types, the behavior is undefined. * If the function accesses passed components after destroying the @@ -129,6 +131,8 @@ namespace psemek::ecs * except for empty component types (i.e. std::is_empty_v is true), * each having an unspecified non-zero size. * An optional query cache can be supplied to speed up iteration. + * If any two of the passed component types are equal, the call fails with + * a compilation error. * If the query cache wasn't created with the exact sequence of component * types, the behavior is undefined. * If the function creates or destroyes entities, the behavior is undefined. @@ -279,6 +283,8 @@ namespace psemek::ecs template void entity_container::apply(Function && function, query_cache cache) { + static_assert(detail::all_different_types_v, "all component types must be different"); + if (!cache) cache = this->cache(); @@ -319,6 +325,8 @@ namespace psemek::ecs template void entity_container::batch_apply(Function && function, query_cache cache) { + static_assert(detail::all_different_types_v, "all component types must be different"); + if (!cache) cache = this->cache();