Function each

Summary

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

(1) template <typename Func>
    void each(Func func) const

(2) iterable_group each() const noexcept

Function overload

Synopsis

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

template <typename Func>
void each(Func func) const

Description

Iterates entities and components and applies the given function object to them.

The function object is invoked for each entity. It is provided with the entity itself and a set of references to non-empty components. The constness of the components is as requested.
The signature of the function must be equivalent to one of the following forms:

void(const entity_type, Type &...);
void(Type &...);
Note
Empty types aren't explicitly instantiated and therefore they are never returned during iterations.
Template Parameters

Func - Type of the function object to invoke.

Parameters

func - A valid function object.

Source

Lines 842-851 in src/entt/entity/group.hpp.

template<typename Func>
void each(Func func) const {
    for(auto args: each()) {
        if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_group>().get({})))>) {
            std::apply(func, args);
        } else {
            std::apply([&func](auto, auto &&... less) { func(std::forward<decltype(less)>(less)...); }, args);
        }
    }
}

Synopsis

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

iterable_group each() const noexcept

Description

Returns an iterable object to use to visit the group.

The iterable object returns tuples that contain the current entity and a set of references to its non-empty components. The constness of the components is as requested.

Note
Empty types aren't explicitly instantiated and therefore they are never returned during iterations.
Return
An iterable object to use to visit the group.

Source

Lines 866-868 in src/entt/entity/group.hpp.

[[nodiscard]] iterable_group each() const ENTT_NOEXCEPT {
    return iterable_group{pools, *length};
}





Add Discussion

Log in to comment