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

This commit is contained in:
Michele Caini
2020-03-11 16:19:41 +01:00
parent 23a73fcb7c
commit 9aadc30b94
+34 -6
View File
@@ -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.
*