storage: disambiguate calls to ::construct (see #438)

This commit is contained in:
Michele Caini
2020-03-11 00:00:51 +01:00
parent dc8fa2153b
commit d8f289182d

View File

@@ -317,7 +317,7 @@ public:
* @param args Parameters to use to construct an object for the entity.
*/
template<typename... Args>
void construct(const entity_type entt, Args &&... args) {
void emplace(const entity_type entt, Args &&... args) {
if constexpr(std::is_aggregate_v<object_type>) {
instances.push_back(Type{std::forward<Args>(args)...});
} else {
@@ -328,6 +328,13 @@ public:
underlying_type::construct(entt);
}
/*! @copydoc emplace */
template<typename... Args>
[[deprecated("use ::emplace instead")]]
void construct(const entity_type entt, Args &&... args) {
emplace(entt, std::forward<Args>(args)...);
}
/**
* @brief Assigns one or more entities to a storage and constructs their
* objects from a given instance.
@@ -344,13 +351,20 @@ public:
* @param value An instance of the object to construct.
*/
template<typename It>
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
construct(It first, It last, const object_type &value = {}) {
void insert(It first, It last, const object_type &value = {}) {
instances.insert(instances.end(), std::distance(first, last), value);
// entities go after components in case constructors throw
underlying_type::construct(first, last);
}
/*! @copydoc insert */
template<typename It>
[[deprecated("use ::insert instead")]]
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
construct(It first, It last, const object_type &value = {}) {
insert(std::move(first), std::move(last), value);
}
/**
* @brief Assigns one or more entities to a storage and constructs their
* objects from a given range.
@@ -364,13 +378,20 @@ public:
* @param value An iterator to the first element of the range of objects.
*/
template<typename EIt, typename CIt>
std::enable_if_t<std::is_same_v<typename std::iterator_traits<EIt>::value_type, entity_type>, void>
construct(EIt first, EIt last, CIt value) {
void insert(EIt first, EIt last, CIt value) {
instances.insert(instances.end(), value, value + std::distance(first, last));
// entities go after components in case constructors throw
underlying_type::construct(first, last);
}
/*! @copydoc insert */
template<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>
construct(EIt first, EIt last, CIt value) {
insert(std::move(first), std::move(last), std::move(value));
}
/**
* @brief Removes an entity from a storage and destroys its object.
*
@@ -675,10 +696,18 @@ public:
* @param entt A valid entity identifier.
*/
template<typename... Args>
void construct(const entity_type entt, Args &&...) {
void emplace(const entity_type entt, Args &&...) {
underlying_type::construct(entt);
}
/*! @copydoc emplace */
template<typename... Args>
[[deprecated("use ::emplace instead")]]
void construct(const entity_type entt, Args &&... args) {
emplace(entt, std::forward<Args>(args)...);
}
/**
* @brief Assigns one or more entities to a storage.
*
@@ -693,11 +722,18 @@ public:
* @param last An iterator past the last element of the range of entities.
*/
template<typename It>
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
construct(It first, It last, const object_type & = {}) {
void insert(It first, It last, const object_type & = {}) {
underlying_type::construct(first, last);
}
/*! @copydoc insert */
template<typename It>
[[deprecated("use ::insert instead")]]
std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
construct(It first, It last, const object_type &value = {}) {
insert(std::move(first), std::move(last), value);
}
/*! @copydoc storage::sort */
template<typename Compare, typename Sort = std_sort, typename... Args>
void sort(iterator_type first, iterator_type last, Compare compare, Sort algo = Sort{}, Args &&... args) {