This commit is contained in:
Michele Caini
2019-02-28 00:06:12 +01:00
parent 4ee4af7fd4
commit eeeca3e21c
2 changed files with 18 additions and 2 deletions

View File

@@ -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)...};
}

View File

@@ -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 *>>));
}