registry: context .clear() function - close #1262

This commit is contained in:
skypjack
2025-06-03 10:49:10 +02:00
parent ae7b3d87ee
commit d7d63b09b7
2 changed files with 12 additions and 0 deletions

View File

@@ -164,6 +164,10 @@ public:
explicit registry_context(const allocator_type &allocator)
: ctx{allocator} {}
void clear() noexcept {
ctx.clear();
}
template<typename Type, typename... Args>
Type &emplace_as(const id_type id, Args &&...args) {
return any_cast<Type &>(ctx.try_emplace(id, std::in_place_type<Type>, std::forward<Args>(args)...).first->second);

View File

@@ -2353,6 +2353,14 @@ TEST(Registry, Context) {
ASSERT_EQ(ctx.find<const int>(), cctx.find<int>());
ASSERT_EQ(ctx.get<int>(), cctx.get<const int>());
ASSERT_EQ(ctx.get<int>(), 0);
ASSERT_TRUE(ctx.contains<char>());
ASSERT_TRUE(ctx.contains<int>());
ctx.clear();
ASSERT_FALSE(ctx.contains<char>());
ASSERT_FALSE(ctx.contains<int>());
}
TEST(Registry, ContextHint) {