
Hello, I have written this code to return 2 to the power x. #include <boost/preprocessor/repetition/for.hpp> #include <boost/preprocessor/seq/size.hpp> #include <boost/preprocessor/arithmetic/add.hpp> #include <boost/preprocessor/arithmetic/sub.hpp> #include <boost/preprocessor/arithmetic/mul.hpp> #include <boost/preprocessor/tuple/elem.hpp> #include <boost/preprocessor/seq/elem.hpp> #define PRED(r,state) BOOST_PP_TUPLE_ELEM(2, 1, state) #define OP(r,state) (BOOST_PP_MUL(BOOST_PP_TUPLE_ELEM(2, 0, state), 2), BOOST_PP_SUB(BOOST_PP_TUPLE_ELEM(2, 1, state), 1)) #define MACRO(r,state) (state) #define POWERSEQ(x) BOOST_PP_FOR((2,x), PRED, OP, MACRO) #define LAST_TUPLE(x) BOOST_PP_SEQ_ELEM(BOOST_PP_SUB(BOOST_PP_SEQ_SIZE(POWERSEQ(x)),1), POWERSEQ(x)) #define POWER2(x) BOOST_PP_TUPLE_ELEM(2, 0, LAST_TUPLE(x)) POWER2(6) I have to generate some sequence and take the last element of it and then extract the result. I didn't find such a macro already in PP. My code seems a bit too complicated. Is there a more trivial way to do this? rds,