From 9aadc30b94fc6beee076b35bee98bab306f7f4ed Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 11 Mar 2020 16:19:41 +0100 Subject: [PATCH] registry: disambiguate calls to ::assign and ::assign_or_replace (close #438) --- src/entt/entity/registry.hpp | 40 ++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index 99403cae1..0bc1d2320 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -586,11 +586,18 @@ public: * @return A reference to the newly created component. */ template - decltype(auto) assign(const entity_type entity, Args &&... args) { + decltype(auto) emplace(const entity_type entity, Args &&... args) { ENTT_ASSERT(valid(entity)); return assure().emplace(*this, entity, std::forward(args)...); } + /*! @copydoc emplace */ + template + [[deprecated("use ::emplace instead")]] + decltype(auto) assign(const entity_type entity, Args &&... args) { + return emplace(entity, std::forward(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 - std::enable_if_t::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().insert(*this, first, last, value); } + /*! @copydoc insert */ + template + [[deprecated("use ::insert instead")]] + std::enable_if_t::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 - std::enable_if_t::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().insert(*this, first, last, value); } + /*! @copydoc insert */ + template + [[deprecated("use ::insert instead")]] + std::enable_if_t::value_type, entity_type>, void> + assign(EIt first, EIt last, CIt value) { + return insert(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 - 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(); @@ -691,6 +712,13 @@ public: : cpool.emplace(*this, entity, std::forward(args)...); } + /*! @copydoc emplace_or_replace */ + template + [[deprecated("use ::emplace_or_replace instead")]] + decltype(auto) assign_or_replace(const entity_type entity, Args &&... args) { + return emplace_or_replace(entity, std::forward(args)...); + } + /** * @brief Patches the given component for an entity. *