How do I iterate over/get static members from the variadic template types in a function with no arguments?

197 views Asked by At

I need to write a function for an ECS that takes in a variable number of template parameters (Components) and no arguments and will return a list of entities with those components attached.

The format would look like this:

auto list = registry.getEntityGroupWithComponents<TransformComponent, RenderComponent>();

Within the function, I need to access a static ID of each Component class to determine which entities to return, something like this:

template <class... T>
std::vector<Entity> getEntityGroupWithComponents()
{
     auto componentIDs = { T::s_id };
     //return entities with all componentIDs in list
}

I've messed around quite a bit and can't come up with anything that produces this behavior, but I'm fairly sure it's possible since I think I've seen a similar API before. Any help would be appreciated, thanks!

1

There are 1 answers

5
bipll On

Unsure about what you need, but probably something like

template <class... T>
std::vector<Entity> getEntityGroupWithComponents()
{
    return {enitity(T::s_id)...};
}

?

Depending on how an entity is constructed from a component id.