From 08b14ded933fdadb9cac381347f09195daafc63e Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sat, 16 Dec 2023 21:55:59 +0300 Subject: [PATCH] Add static_assert to notify when a function is not invocable in ecs::container::apply & batch_apply --- libs/ecs/include/psemek/ecs/container.hpp | 2 ++ .../include/psemek/ecs/detail/apply_helper.hpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/libs/ecs/include/psemek/ecs/container.hpp b/libs/ecs/include/psemek/ecs/container.hpp index 9da9497e..c3caa449 100644 --- a/libs/ecs/include/psemek/ecs/container.hpp +++ b/libs/ecs/include/psemek/ecs/container.hpp @@ -451,6 +451,7 @@ namespace psemek::ecs query_cache container::apply(Function && function, query_cache cache) { static_assert(detail::all_different_types_v...>, "all component types must be different"); + static_assert(detail::invocable, "function is not invocable with these components"); if (!cache) cache = this->cache(); @@ -495,6 +496,7 @@ namespace psemek::ecs query_cache container::batch_apply(Function && function, query_cache cache) { static_assert(detail::all_different_types_v...>, "all component types must be different"); + static_assert(detail::batch_invocable, "function is not batch-invocable with these components"); if (!cache) cache = this->cache(); diff --git a/libs/ecs/include/psemek/ecs/detail/apply_helper.hpp b/libs/ecs/include/psemek/ecs/detail/apply_helper.hpp index a3af84c9..27d31fa0 100644 --- a/libs/ecs/include/psemek/ecs/detail/apply_helper.hpp +++ b/libs/ecs/include/psemek/ecs/detail/apply_helper.hpp @@ -15,6 +15,14 @@ namespace psemek::ecs namespace psemek::ecs::detail { + template + constexpr bool invocable = false + || std::invocable + || std::invocable + || std::invocable + || std::invocable + ; + template void invoke(Function && function, container & parent, handle const & handle, Components & ... components) { @@ -36,6 +44,14 @@ namespace psemek::ecs::detail } } + template + constexpr bool batch_invocable = false + || std::invocable, util::span ...> + || std::invocable ...> + || std::invocable, util::span ...> + || std::invocable ...> + ; + template void batch_invoke(Function && function, container & parent, std::size_t count, handle const * handles, Components * ... components) {