I hava a macro to call static function for each args.
For example:
#define FOO(X) X::do();
#define FOO_1(X,Y) X::do(); Y::do();
My
Macro expansion does not work like argument pack expansion with variadic templates. What you have will expand to:
X,Y::do();
And not to
X::do(); Y::do();
As you hoped. But in C++11 you could use variadic templates. For instance, you could do what you want this way:
#include
struct X { static void foo() { std::cout << "X::foo()" << std::endl; }; };
struct Y { static void foo() { std::cout << "Y::foo()" << std::endl; }; };
struct Z { static void foo() { std::cout << "Z::foo()" << std::endl; }; };
int main()
{
do_foo();
}
All you need is this (relatively simple) machinery:
namespace detail
{
template
struct do_foo;
template
struct do_foo
{
static void call()
{
T::foo();
do_foo::call();
}
};
template
struct do_foo
{
static void call()
{
T::foo();
}
};
}
template
void do_foo()
{
detail::do_foo::call();
}
Here is a live example.