Trouble with __VA_ARGS__
Posted
by
Noah Roberts
on Stack Overflow
See other posts from Stack Overflow
or by Noah Roberts
Published on 2011-01-07T22:55:15Z
Indexed on
2011/01/07
23:54 UTC
Read the original article
Hit count: 329
C++ preprocessor __VA_ARGS__ number of arguments
The accepted answer there doesn't work for me. I've tried with MSVC++ 10 and g++ 3.4.5.
I also crunched the example down into something smaller and started trying to get some information printed out to me in the error:
template < typename T >
struct print;
#include <boost/mpl/vector_c.hpp>
#define RSEQ_N 10,9,8,7,6,5,4,3,2,1,0
#define ARG_N(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,N,...) N
#define ARG_N_(...) ARG_N(__VA_ARGS__)
#define XXX 5,RSEQ_N
#include <iostream>
int main()
{
print< boost::mpl::vector_c<int, ARG_N_( XXX ) > > g; // ARG_N doesn't work either.
}
It appears to me that the argument for ARG_N ends up being 'XXX' instead of 5,RSEQ_N
and much less 5,10,...,0
. The error output of g++ more specifically says that only one argument is supplied.
Having trouble believing that the answer would be proposed and then accepted when it totally fails to work, so what am I doing wrong? Why is XXX
being interpreted as the argument and not being expanded? In my own messing around everything works fine until I try to pass off VA_ARGS to a macro containing some names followed by ... like so:
#define WTF(X,Y,...) X , Y , __VA_ARGS__
#define WOT(...) WTF(__VA_ARGS__)
WOT(52,2,5,2,2)
I've tried both with and without ()
in the various macros that take no input.
© Stack Overflow or respective owner