Function try_get

Summary

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

(1) template <typename... Component>
    auto try_get([[maybe_unused]] const entity_type entity) const

(2) template <typename... Component>
    auto try_get([[maybe_unused]] const entity_type entity)

Function overload

Synopsis

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

template <typename... Component>
auto try_get([[maybe_unused]] const entity_type entity) const

Description

Returns pointers to the given components for an entity.

Warning
Attempting to use an invalid entity results in undefined behavior.
Note
The registry retains ownership of the pointed-to components.
Template Parameters

Component - Types of components to get.

Parameters

entity - A valid entity identifier.

Return
Pointers to the components owned by the entity.

Source

Lines 877-887 in src/entt/entity/registry.hpp.

template<typename... Component>
[[nodiscard]] auto try_get([[maybe_unused]] const entity_type entity) const {
    ENTT_ASSERT(valid(entity));
    if constexpr(sizeof...(Component) == 1) {
        auto &cpool = assure<Component...>();
        return cpool.contains(entity) ? &cpool.get(entity) : nullptr;
    } else {
        return std::make_tuple(try_get<Component>(entity)...);
    }
}

Synopsis

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

template <typename... Component>
auto try_get([[maybe_unused]] const entity_type entity)

Description

Returns pointers to the given components for an entity.

Warning
Attempting to use an invalid entity results in undefined behavior.
Note
The registry retains ownership of the pointed-to components.
Template Parameters

Component - Types of components to get.

Parameters

entity - A valid entity identifier.

Return
Pointers to the components owned by the entity.

Source

Lines 890-900 in src/entt/entity/registry.hpp.

template<typename... Component>
[[nodiscard]] auto try_get([[maybe_unused]] const entity_type entity) {
    ENTT_ASSERT(valid(entity));
    if constexpr(sizeof...(Component) == 1) {
        auto &cpool = assure<Component...>();
        return cpool.contains(entity) ? &cpool.get(entity) : nullptr;
    } else {
        return std::make_tuple(try_get<Component>(entity)...);
    }
}





Add Discussion

Log in to comment