Class RecursiveChildIterator

Class Documentation

class RecursiveChildIterator

Forward iterator for depth-first traversal of all descendants.

RecursiveChildIterator provides STL-compliant forward iteration over an entity’s entire subtree using depth-first traversal. It maintains an internal stack to track pending nodes, avoiding recursion overhead.

The iterator uses llvm::SmallVector with an 8-entity inline capacity for the stack, optimizing for typical hierarchy depths without heap allocations.

See also

RecursiveChildRange for the range wrapper

See also

ChildIterator for non-recursive direct children iteration

Example:
for (auto descendant : entity.descendants()) {
    // Processes entire subtree in depth-first order
    descendant.get_component<TransformComponent>();
}

Public Types

using iterator_category = std::forward_iterator_tag
using value_type = Entity
using difference_type = std::ptrdiff_t
using pointer = value_type*
using reference = value_type&

Public Functions

RecursiveChildIterator(entt::entity start, entt::registry *registry, bool is_end = false)

Constructs an iterator for recursive traversal.

Parameters:
  • start – The root entity to begin traversal from

  • registry – Pointer to the registry containing entities

  • is_end – If true, constructs an end sentinel iterator

Entity operator*() const

Dereferences the iterator to access the current descendant.

Returns:

The current descendant as an Entity wrapper

Entity operator->() const

Arrow operator for accessing the current descendant.

Returns:

The current descendant as an Entity wrapper

RecursiveChildIterator &operator++()

Advances to the next descendant in depth-first order.

Returns:

Reference to this iterator

RecursiveChildIterator operator++(int)

Post-increment (advances to next descendant).

Returns:

Copy of the iterator before advancement

bool operator==(const RecursiveChildIterator &other) const

Compares iterators for equality.

Parameters:

other – The iterator to compare against

Returns:

true if both iterators point to the same entity

bool operator!=(const RecursiveChildIterator &other) const

Compares iterators for inequality.

Parameters:

other – The iterator to compare against

Returns:

true if iterators point to different entities