Просмотр исходного кода

registry: disambiguate calls to ::assign and ::assign_or_replace (close #438)

Michele Caini 6 лет назад
Родитель
Сommit
9aadc30b94
1 измененных файлов с 34 добавлено и 6 удалено
  1. 34 6
      src/entt/entity/registry.hpp

+ 34 - 6
src/entt/entity/registry.hpp

@@ -586,11 +586,18 @@ public:
      * @return A reference to the newly created component.
      */
     template<typename Component, typename... Args>
-    decltype(auto) assign(const entity_type entity, Args &&... args) {
+    decltype(auto) emplace(const entity_type entity, Args &&... args) {
         ENTT_ASSERT(valid(entity));
         return assure<Component>().emplace(*this, entity, std::forward<Args>(args)...);
     }
 
+    /*! @copydoc emplace */
+    template<typename Component, typename... Args>
+    [[deprecated("use ::emplace instead")]]
+    decltype(auto) assign(const entity_type entity, Args &&... args) {
+        return emplace<Component>(entity, std::forward<Args>(args)...);
+    }
+
     /**
      * @brief Assigns each entity in a range the given component.
      *
@@ -603,12 +610,19 @@ public:
      * @param value An instance of the component to assign.
      */
     template<typename Component, typename It>
-    std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
-    assign(It first, It last, const Component &value = {}) {
+    void insert(It first, It last, const Component &value = {}) {
         ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); }));
         assure<Component>().insert(*this, first, last, value);
     }
 
+    /*! @copydoc insert */
+    template<typename Component, typename It>
+    [[deprecated("use ::insert instead")]]
+    std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
+    assign(It first, It last, const Component &value = {}) {
+        return insert(std::move(first), std::move(last), value);
+    }
+
     /**
      * @brief Assigns each entity in a range the given components.
      *
@@ -622,12 +636,19 @@ public:
      * @param value An iterator to the first element of the range of components.
      */
     template<typename Component, typename EIt, typename CIt>
-    std::enable_if_t<std::is_same_v<typename std::iterator_traits<EIt>::value_type, entity_type>, void>
-    assign(EIt first, EIt last, CIt value) {
+    void insert(EIt first, EIt last, CIt value) {
         ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); }));
         assure<Component>().insert(*this, first, last, value);
     }
 
+    /*! @copydoc insert */
+    template<typename Component, typename EIt, typename CIt>
+    [[deprecated("use ::insert instead")]]
+    std::enable_if_t<std::is_same_v<typename std::iterator_traits<EIt>::value_type, entity_type>, void>
+    assign(EIt first, EIt last, CIt value) {
+        return insert<Component>(std::move(first), std::move(last), std::move(value));
+    }
+
     /**
      * @brief Assigns entities to an empty registry.
      *
@@ -682,7 +703,7 @@ public:
      * @return A reference to the newly created component.
      */
     template<typename Component, typename... Args>
-    decltype(auto) assign_or_replace(const entity_type entity, Args &&... args) {
+    decltype(auto) emplace_or_replace(const entity_type entity, Args &&... args) {
         ENTT_ASSERT(valid(entity));
         auto &cpool = assure<Component>();
 
@@ -691,6 +712,13 @@ public:
                 : cpool.emplace(*this, entity, std::forward<Args>(args)...);
     }
 
+    /*! @copydoc emplace_or_replace */
+    template<typename Component, typename... Args>
+    [[deprecated("use ::emplace_or_replace instead")]]
+    decltype(auto) assign_or_replace(const entity_type entity, Args &&... args) {
+        return emplace_or_replace<Component>(entity, std::forward<Args>(args)...);
+    }
+
     /**
      * @brief Patches the given component for an entity.
      *