Hello,
I have written this code to return 2 to the power x.
#include
#include
#include
#include
#include
#include
#include
#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,