storage: reintroduce support to args for empty types - see #1323

This commit is contained in:
skypjack
2026-03-16 14:10:10 +01:00
parent 9c5281c79a
commit 6ca3db7de4
5 changed files with 24 additions and 25 deletions

View File

@@ -571,21 +571,6 @@ public:
return assure<Type>().emplace(entt, std::forward<Args>(args)...);
}
/**
* @brief Assigns each entity in a range the given element.
*
* @sa emplace
*
* @tparam Type Type of element to create.
* @param first An iterator to the first element of the range of entities.
* @param last An iterator past the last element of the range of entities.
*/
template<typename Type>
void insert(stl::input_iterator auto first, stl::input_iterator auto last) {
ENTT_ASSERT(std::all_of(first, last, [this](const auto entt) { return valid(entt); }), "Invalid entity");
assure<Type>().insert(std::move(first), std::move(last));
}
/**
* @brief Assigns each entity in a range the given element.
*
@@ -597,7 +582,7 @@ public:
* @param value An instance of the element to assign.
*/
template<typename Type>
void insert(stl::input_iterator auto first, stl::input_iterator auto last, const Type &value) {
void insert(stl::input_iterator auto first, stl::input_iterator auto last, const Type &value = {}) {
ENTT_ASSERT(std::all_of(first, last, [this](const auto entt) { return valid(entt); }), "Invalid entity");
assure<Type>().insert(std::move(first), std::move(last), value);
}

View File

@@ -890,9 +890,12 @@ public:
* Attempting to use an entity that already belongs to the storage results
* in undefined behavior.
*
* @tparam Args Types of arguments to use to construct the object.
* @param entt A valid identifier.
*/
void emplace(const entity_type entt) {
template<typename... Args>
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
auto emplace(const entity_type entt, Args &&...) {
base_type::try_emplace(entt, false);
}
@@ -911,11 +914,13 @@ public:
/**
* @brief Assigns entities to a storage.
* @tparam It Type of input iterator.
* @tparam Args Types of optional arguments.
* @param first An iterator to the first element of the range of entities.
* @param last An iterator past the last element of the range of entities.
*/
template<stl::input_iterator It>
void insert(It first, It last) {
template<typename It, typename... Args>
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
void insert(It first, It last, Args &&...) {
for(; first != last; ++first) {
base_type::try_emplace(*first, true);
}