Add static asserts in ecs::entity_component::apply/batch_apply to check that all component types are different

This commit is contained in:
Nikita Lisitsa 2023-08-26 22:11:55 +03:00
parent f46b3bdc40
commit 85c0c56e03

View file

@ -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<Component> 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 <typename ... Components, typename Function>
void entity_container::apply(Function && function, query_cache cache)
{
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
if (!cache)
cache = this->cache<Components...>();
@ -319,6 +325,8 @@ namespace psemek::ecs
template <typename ... Components, typename Function>
void entity_container::batch_apply(Function && function, query_cache cache)
{
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
if (!cache)
cache = this->cache<Components...>();