fix #194
This commit is contained in:
@@ -660,7 +660,7 @@ public:
|
||||
assert(valid(entity));
|
||||
|
||||
if constexpr(sizeof...(Component) == 1) {
|
||||
return (std::get<1>(pool<Component>())->get(entity), ...);
|
||||
return (std::as_const(*std::get<1>(pool<Component>())).get(entity), ...);
|
||||
} else {
|
||||
return std::tuple<std::add_const_t<Component> &...>{get<Component>(entity)...};
|
||||
}
|
||||
@@ -730,7 +730,7 @@ public:
|
||||
assert(valid(entity));
|
||||
|
||||
if constexpr(sizeof...(Component) == 1) {
|
||||
return (std::get<1>(assure<Component>())->try_get(entity), ...);
|
||||
return (std::as_const(*std::get<1>(assure<Component>())).try_get(entity), ...);
|
||||
} else {
|
||||
return std::tuple<std::add_const_t<Component> *...>{try_get<Component>(entity)...};
|
||||
}
|
||||
|
||||
@@ -1127,3 +1127,19 @@ TEST(Registry, GetOrAssign) {
|
||||
ASSERT_EQ(registry.get<int>(entity), value);
|
||||
ASSERT_EQ(registry.get<int>(entity), 3);
|
||||
}
|
||||
|
||||
TEST(Registry, Constness) {
|
||||
entt::registry<> registry;
|
||||
|
||||
ASSERT_TRUE((std::is_same_v<decltype(registry.get<int>({})), int &>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(registry.get<int, char>({})), std::tuple<int &, char &>>));
|
||||
|
||||
ASSERT_TRUE((std::is_same_v<decltype(registry.try_get<int>({})), int *>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(registry.try_get<int, char>({})), std::tuple<int *, char *>>));
|
||||
|
||||
ASSERT_TRUE((std::is_same_v<decltype(std::as_const(registry).get<int>({})), const int &>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(std::as_const(registry).get<int, char>({})), std::tuple<const int &, const char &>>));
|
||||
|
||||
ASSERT_TRUE((std::is_same_v<decltype(std::as_const(registry).try_get<int>({})), const int *>));
|
||||
ASSERT_TRUE((std::is_same_v<decltype(std::as_const(registry).try_get<int, char>({})), std::tuple<const int *, const char *>>));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user