[Boost-users] [preprocessor] error: macro "BOOST_PP_SEQ_ELEM_III"

115 views
Skip to first unread message

Reimund Klemm

unread,
Mar 12, 2009, 3:51:16 AM3/12/09
to boost...@lists.boost.org
I'm having a problem with the preprocessor and currently I'm stuck. I
tried to reduce the problem from my program as far as possible.

Why does this example compile with an error?:

#include <boost/preprocessor/seq/subseq.hpp>
#include <boost/preprocessor/seq/seq.hpp>
#include <boost/preprocessor/control/if.hpp>

#define SEQ (b)(o)(o)(s)(t)
#define i 0

int main( int argc, char* argv[]){
BOOST_PP_IF(i,BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_SUBSEQ(SEQ, 0, i)),0);
return 0;
}

The error is the following:

./test.cxx:23:1: error: macro "BOOST_PP_SEQ_ELEM_III" requires 2
arguments, but only 1 given

I'm using gcc 4.3.1 under Linux.

As the condition is 0, the preprocessor shouldn't expand
BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_SUBSEQ(SEQ, 0, i)).
The preprocessed file (g++ -P -E) has expands to 0; but the preprocessor
still throws an error.

Could also someone give me a hint how to debug efficiently such a
problem, as I'm a newbie to boost.

---
Reimund

'Reimund Klemm (klemm@ifn.et.tu-dresden.de)'.vcf

Peter Bartlett

unread,
Mar 12, 2009, 4:27:39 AM3/12/09
to boost...@lists.boost.org
Quoting Reimund Klemm <kl...@ifn.et.tu-dresden.de>:

> Why does this example compile with an error?:
>
> #include <boost/preprocessor/seq/subseq.hpp>
> #include <boost/preprocessor/seq/seq.hpp>
> #include <boost/preprocessor/control/if.hpp>
>
> #define SEQ (b)(o)(o)(s)(t)
> #define i 0
>
> int main( int argc, char* argv[]){
> BOOST_PP_IF(i,BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_SUBSEQ(SEQ, 0, i)),0);
> return 0;
> }
>

You need to delay the evaluation of the branches. E.g.

#include <boost/preprocessor/seq/subseq.hpp>
#include <boost/preprocessor/seq/seq.hpp>
#include <boost/preprocessor/control/if.hpp>

#define SEQ (b)(o)(o)(s)(t)
#define i 0

#define TRUE_BRANCH(SEQ)\
BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_SUBSEQ(SEQ,0,i))\
/**/

#define FALSE_BRANCH(SEQ) 0

int main( int argc, char* argv[]){

BOOST_PP_IF(i,TRUE_BRANCH,FALSE_BRANCH)(SEQ);
return 0;
}

should work.

Pete


_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Reimund Klemm

unread,
Mar 12, 2009, 5:14:40 AM3/12/09
to boost...@lists.boost.org

Now it works,

Thanks Pete!

Reply all
Reply to author
Forward
0 new messages