简体   繁体   English

如何在没有 arguments 的 function 中迭代/获取 static 成员?

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

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.我需要为一个 ECS 编写一个 function,它接受可变数量的模板参数(组件)并且没有 arguments,并将返回附有这些组件的实体列表。

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:在 function 中,我需要访问每个组件 class 的 static ID 以确定要返回的实体,如下所示:

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.我已经搞砸了很多,无法想出任何会产生这种行为的东西,但我很确定这是可能的,因为我认为我以前见过类似的 API。 Any help would be appreciated, thanks!任何帮助将不胜感激,谢谢!

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.取决于如何从组件 id 构造实体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM