As the title says, I'm trying to create something to be used as followed :
template <typename T>
void testFunc(int& i)
{
...
}
int i { 0 };
ForEach<int, float>::run<testFunc>(i);
I've already tried some things, but I'm hitting some problems:
template<typename CurrentComponentType, typename... ComponentTypes>
struct ForEach
{
template<void (&func)(auto&&... args)>
static constexpr void run(auto&&... args)
{
func<CurrentComponentType>(std::forward<decltype(args)>(args)...);
ForEach<ComponentTypes...>::run<func>(std::forward<decltype(args)>(args)...);
}
};
template<typename CurrentComponentType>
struct ForEach<CurrentComponentType>
{
template<void (&func)(auto&&... args)>
static constexpr void run(auto&&... args)
{
func<CurrentComponentType>(std::forward<decltype(args)>(args)...);
}
};
I don't know how to take a template function as a (template but not necessarily) argument.
For some reasons that I don't understand, I cannot call again the
run()
function as so:run<func>(
. It says'<unresolved overloaded function type>'
.
I think there are multiple things I don't understand.
How can I fix it, and why doesn't it work this way? What am I misunderstanding?