diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index a8841ecfe..487ce9281 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -164,6 +164,10 @@ public: explicit registry_context(const allocator_type &allocator) : ctx{allocator} {} + void clear() noexcept { + ctx.clear(); + } + template Type &emplace_as(const id_type id, Args &&...args) { return any_cast(ctx.try_emplace(id, std::in_place_type, std::forward(args)...).first->second); diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index e4cf431c2..cc992af27 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -2353,6 +2353,14 @@ TEST(Registry, Context) { ASSERT_EQ(ctx.find(), cctx.find()); ASSERT_EQ(ctx.get(), cctx.get()); ASSERT_EQ(ctx.get(), 0); + + ASSERT_TRUE(ctx.contains()); + ASSERT_TRUE(ctx.contains()); + + ctx.clear(); + + ASSERT_FALSE(ctx.contains()); + ASSERT_FALSE(ctx.contains()); } TEST(Registry, ContextHint) {