diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index d8f3e1c4a..13dcf1c0d 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -178,12 +178,22 @@ public: } template - [[nodiscard]] const Type &at(const id_type id = type_id().hash()) const { + [[deprecated("Use ::get instead")]] [[nodiscard]] const Type &at(const id_type id = type_id().hash()) const { + return get(id); + } + + template + [[deprecated("Use ::get instead")]] [[nodiscard]] Type &at(const id_type id = type_id().hash()) { + return get(id); + } + + template + [[nodiscard]] const Type &get(const id_type id = type_id().hash()) const { return any_cast(ctx.at(id)); } template - [[nodiscard]] Type &at(const id_type id = type_id().hash()) { + [[nodiscard]] Type &get(const id_type id = type_id().hash()) { return any_cast(ctx.at(id)); } diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index 35e0e254c..e1dff4081 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -102,8 +102,8 @@ TEST(Registry, Context) { ASSERT_EQ(ctx.emplace('a'), 'c'); ASSERT_EQ(ctx.find(), cctx.find()); - ASSERT_EQ(ctx.at(), cctx.at()); - ASSERT_EQ(ctx.at(), 'c'); + ASSERT_EQ(ctx.get(), cctx.get()); + ASSERT_EQ(ctx.get(), 'c'); ASSERT_EQ(ctx.emplace(0), 42); ASSERT_EQ(ctx.find(), cctx.find()); @@ -132,14 +132,14 @@ TEST(Registry, ContextHint) { ASSERT_NE(ctx.find("other"_hs), nullptr); ASSERT_EQ(cctx.find("other"_hs), nullptr); - ASSERT_EQ(ctx.at(), 42); - ASSERT_EQ(cctx.at("other"_hs), 3); + ASSERT_EQ(ctx.get(), 42); + ASSERT_EQ(cctx.get("other"_hs), 3); ASSERT_FALSE(ctx.erase("other"_hs)); ASSERT_TRUE(ctx.erase()); ASSERT_TRUE(cctx.contains("other"_hs)); - ASSERT_EQ(ctx.at("other"_hs), 3); + ASSERT_EQ(ctx.get("other"_hs), 3); ASSERT_TRUE(ctx.erase("other"_hs)); @@ -156,17 +156,17 @@ TEST(Registry, ContextAsRef) { ASSERT_NE(registry.ctx().find(), nullptr); ASSERT_NE(registry.ctx().find(), nullptr); ASSERT_NE(std::as_const(registry).ctx().find(), nullptr); - ASSERT_EQ(registry.ctx().at(), 3); - ASSERT_EQ(registry.ctx().at(), 3); + ASSERT_EQ(registry.ctx().get(), 3); + ASSERT_EQ(registry.ctx().get(), 3); - registry.ctx().at() = 42; + registry.ctx().get() = 42; - ASSERT_EQ(registry.ctx().at(), 42); + ASSERT_EQ(registry.ctx().get(), 42); ASSERT_EQ(value, 42); value = 3; - ASSERT_EQ(std::as_const(registry).ctx().at(), 3); + ASSERT_EQ(std::as_const(registry).ctx().get(), 3); } TEST(Registry, ContextAsConstRef) { @@ -178,11 +178,11 @@ TEST(Registry, ContextAsConstRef) { ASSERT_EQ(registry.ctx().find(), nullptr); ASSERT_NE(registry.ctx().find(), nullptr); ASSERT_NE(std::as_const(registry).ctx().find(), nullptr); - ASSERT_EQ(registry.ctx().at(), 3); + ASSERT_EQ(registry.ctx().get(), 3); value = 42; - ASSERT_EQ(std::as_const(registry).ctx().at(), 42); + ASSERT_EQ(std::as_const(registry).ctx().get(), 42); } TEST(Registry, Functionalities) { @@ -1827,8 +1827,8 @@ TEST(Registry, Constness) { static_assert((std::is_same_v({})), int *>)); static_assert((std::is_same_v({})), std::tuple>)); - static_assert((std::is_same_v()), int &>)); - static_assert((std::is_same_v()), const char &>)); + static_assert((std::is_same_v()), int &>)); + static_assert((std::is_same_v()), const char &>)); static_assert((std::is_same_v()), int *>)); static_assert((std::is_same_v()), const char *>)); @@ -1839,8 +1839,8 @@ TEST(Registry, Constness) { static_assert((std::is_same_v({})), const int *>)); static_assert((std::is_same_v({})), std::tuple>)); - static_assert((std::is_same_v()), const int &>)); - static_assert((std::is_same_v()), const char &>)); + static_assert((std::is_same_v()), const int &>)); + static_assert((std::is_same_v()), const char &>)); static_assert((std::is_same_v()), const int *>)); static_assert((std::is_same_v()), const char *>));