|
Boost Users : |
Subject: Re: [Boost-users] [preprocessor] error: macro "BOOST_PP_SEQ_ELEM_III"
From: Peter Bartlett (pete_at_[hidden])
Date: 2009-03-12 04:27:39
Quoting Reimund Klemm <klemm_at_[hidden]>:
> 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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net