File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -929,8 +929,7 @@ class basic_registry {
929
929
template <typename ... Type>
930
930
[[nodiscard]] auto try_get ([[maybe_unused]] const entity_type entt) {
931
931
if constexpr (sizeof ...(Type) == 1u ) {
932
- auto &cpool = assure<std::remove_const_t <Type>...>();
933
- return (static_cast <Type *>(cpool.contains (entt) ? std::addressof (cpool.get (entt)) : nullptr ), ...);
932
+ return (const_cast <Type *>(std::as_const (*this ).template try_get <Type>(entt)), ...);
934
933
} else {
935
934
return std::make_tuple (try_get<Type>(entt)...);
936
935
}
Original file line number Diff line number Diff line change @@ -1893,6 +1893,23 @@ TEST(Registry, GetOrEmplace) {
1893
1893
ASSERT_EQ (registry.get <int >(entity), 3 );
1894
1894
}
1895
1895
1896
+ TEST (Registry, TryGet) {
1897
+ entt::registry registry;
1898
+ const auto entity = registry.create ();
1899
+
1900
+ ASSERT_EQ (registry.try_get <int >(entity), nullptr );
1901
+ ASSERT_EQ (std::as_const (registry).try_get <int >(entity), nullptr );
1902
+
1903
+ ASSERT_EQ (std::as_const (registry).storage <int >(), nullptr );
1904
+
1905
+ const int &elem = registry.emplace <int >(entity);
1906
+
1907
+ ASSERT_NE (std::as_const (registry).storage <int >(), nullptr );
1908
+
1909
+ ASSERT_EQ (registry.try_get <int >(entity), &elem);
1910
+ ASSERT_EQ (std::as_const (registry).try_get <int >(entity), &elem);
1911
+ }
1912
+
1896
1913
TEST (Registry, Constness) {
1897
1914
entt::registry registry;
1898
1915
You can’t perform that action at this time.
0 commit comments