#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)))))))))
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt)