I have a member funtion like this:
class Foo
{
public:
template<typename... Args>
static void bar(const Args&... args)
{
/* code */
}
};
And I want to pass it as a template parameter to a member function like this:
class Example
{
public:
template<typename... Args, typename T> // <- ???
void doStuff(const Args&... args)
{
T(args...);
}
};
I have tried multiple things here already, but the one that seemed the most promising was this:
class Example
{
public:
template<typename... Args, typename C, void (C::*F)(Args&...)>
void doStuff(const Args&... args)
{
(C::F)(args...);
}
};
Whilst troubleshooting I thought maybe it's because I got the function signature of bar wrong, so I changed the template of doStuff to this:
template<typename... Args, typename C, void (C::*F)(const Args&...)>
Which didn't seem to help.
I suspect it is because I don't define, the template of parameter F, but I don't know how to add that. Or maybe I could get around this all together by passing a lambda as an attribute to doStuff. I didn't try that yet though, and would idealy not want to have to resort to that.
EDIT 2:
Here is a minimum reproducable example:
class Foo
{
public:
template<typename... Args>
static void bar(const Args&... args)
{
/* code */
}
};
class Example
{
public:
template<typename... Args, typename C, void (C::*F)(Args&...)>
void doStuff(const Args&... args)
{
(C::F)(args...);
}
};
class SomeClass
{
public:
Example ex {};
template<typename... Args>
void someFunc(const Args&... args)
{
ex.doStuff<Args..., Foo, &Foo::bar>(args...);
}
};
int main()
{
SomeClass sc {};
sc.someFunc("Some ", "Arguments ", "Here");
return 0;
}
I know, I know, I rushed the question sry
sc.someFunc("Some ", "Arguments ", "Here");doesnt work is not related to how you write the template