Function assign


#include <src/entt/entity/registry.hpp>

template <typename It>
void assign(It first, It last)


Assigns entities to an empty registry.

This function is intended for use in conjunction with raw.
Don't try to inject ranges of randomly generated entities. There is no guarantee that a registry will continue to work properly in this case.

An assertion will abort the execution at runtime in debug mode if all pools aren't empty.
Template Parameters:

It - Type of input iterator.


first - An iterator to the first element of the range of entities.

last - An iterator past the last element of the range of entities.


Lines 487-500 in src/entt/entity/registry.hpp.

template<typename It>
void assign(It first, It last) {
    ENTT_ASSERT(std::all_of(pools.cbegin(), pools.cend(), [](auto &&pdata) { return !pdata.pool || pdata.pool->empty(); }));
    entities.assign(first, last);
    destroyed = null;
    for(std::size_t pos{}, end = entities.size(); pos < end; ++pos) {
        if((to_integral(entities[pos]) & traits_type::entity_mask) != pos) {
            const auto version = to_integral(entities[pos]) & (traits_type::version_mask << traits_type::entity_shift);
            entities[pos] = entity_type{to_integral(destroyed) | version};
            destroyed = entity_type{static_cast<typename traits_type::entity_type>(pos)};

Add Discussion

Log in to comment