Browse Source

registry (close #911):
* added context emplace_as
* deprecated context emplace_hint

Michele Caini 3 years ago
parent
commit
504c7b5d6d
2 changed files with 8 additions and 3 deletions
  1. 7 2
      src/entt/entity/registry.hpp
  2. 1 1
      test/entt/entity/registry.cpp

+ 7 - 2
src/entt/entity/registry.hpp

@@ -162,13 +162,18 @@ class registry_context {
 
 public:
     template<typename Type, typename... Args>
-    Type &emplace_hint(const id_type id, Args &&...args) {
+    [[deprecated("Use ::emplace_as instead")]] Type &emplace_hint(const id_type id, Args &&...args) {
+        return emplace_as<Type>(id, std::forward<Args>(args)...);
+    }
+
+    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);
     }
 
     template<typename Type, typename... Args>
     Type &emplace(Args &&...args) {
-        return emplace_hint<Type>(type_id<Type>().hash(), std::forward<Args>(args)...);
+        return emplace_as<Type>(type_id<Type>().hash(), std::forward<Args>(args)...);
     }
 
     template<typename Type>

+ 1 - 1
test/entt/entity/registry.cpp

@@ -133,7 +133,7 @@ TEST(Registry, ContextHint) {
     const auto &cctx = std::as_const(registry).ctx();
 
     ctx.emplace<int>(42);
-    ctx.emplace_hint<int>("other"_hs, 3);
+    ctx.emplace_as<int>("other"_hs, 3);
 
     ASSERT_TRUE(ctx.contains<int>());
     ASSERT_TRUE(cctx.contains<const int>("other"_hs));