This macro appends two lists.
For example, if
a is (
1, (
2, (
3,
BOOST_PP_NIL))) and
b is (
4, (
5,
BOOST_PP_NIL)),
this macro will expand to:
(1, (2, (3, (4, (5, BOOST_PP_NIL)))))
#include <boost/preprocessor/arithmetic/dec.hpp>
#include <boost/preprocessor/control/while.hpp>
#include <boost/preprocessor/list/append.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
#define LIST (1, (2, (3, BOOST_PP_NIL)))
#define PRED(d, state) BOOST_PP_TUPLE_ELEM(3, 1, state)
#define OP(d, state) \
( \
BOOST_PP_LIST_APPEND_D( \
d, BOOST_PP_TUPLE_ELEM(3, 0, state), \
BOOST_PP_TUPLE_ELEM(3, 2, state) \
), \
BOOST_PP_DEC( \
BOOST_PP_TUPLE_ELEM(3, 1, state) \
), \
BOOST_PP_TUPLE_ELEM(3, 2, state) \
) \
/**/
#define LIST_MULTIPLY(c, list) \
BOOST_PP_TUPLE_ELEM( \
3, 0, \
BOOST_PP_WHILE( \
PRED, OP, \
(BOOST_PP_NIL, c, list) \
) \
) \
/**/
LIST_MULTIPLY(3, LIST)
// expands to (1, (2, (3, (1, (2, (3, (1, (2, (3, BOOST_PP_NIL)))))))))