I am trying use a variadic template in an && statement, but i dont know how to actually do it. Can somebody explain to me how i can programm a function like this one:
using EntitySet = std::vector<Entity>;
template<typename... TArgs>
EntitySet getEntitesWith()
{
EntitySet entitySet;
for(const Entity& entity : m_entitySet)
{
if (entity.hasComponent<T1>() && entity.hasComponent<T2>() && ...)
{
entitySet.push_back(entity);
}
}
return entitySet;
}
entity.hasComponent<>() returns true if the entity has a Component of the type that is passed into the function
Edit:
i just tried the Fold Expression in c++17 and when i tried to do it like @Igor Tandetnik and @oisyn told me to i got an Unexpected ... Token Error. But when i wrote the code like this:
if (( ... && entity.hasComponent<TArgs>()))
With an extra () i got an internal compiler error and have no idea on what im doing wrong. anybody have an idea on why this is happening?