#include <boost/preprocessor/arithmetic/dec.hpp> #include <boost/preprocessor/list/for_each_product.hpp> #include <boost/preprocessor/repetition/for.hpp> #include <boost/preprocessor/tuple/elem.hpp> #define L1 (a, (b, BOOST_PP_NIL)) #define L2 (x, (y, BOOST_PP_NIL)) #define PRED(r, state) BOOST_PP_TUPLE_ELEM(2, 0, state) #define OP(r, state) \ ( \ BOOST_PP_DEC( \ BOOST_PP_TUPLE_ELEM(2, 0, state) \ ), \ BOOST_PP_TUPLE_ELEM(2, 1, state) \ ) \ /**/ #define MACRO(r, state) \ MACRO_I( \ r, \ BOOST_PP_TUPLE_ELEM(2, 0, state), \ BOOST_PP_TUPLE_ELEM(2, 1, state) \ ) \ /**/ #define MACRO_I(r, c, t) \ BOOST_PP_LIST_FOR_EACH_PRODUCT_R( \ r, MACRO_P, 2, \ ( \ BOOST_PP_TUPLE_ELEM(2, BOOST_PP_DEC(c), t), \ BOOST_PP_TUPLE_ELEM(2, BOOST_PP_DEC(c), t) \ ) \ ) \ /**/ #define MACRO_P(r, product) product BOOST_PP_FOR((2, (L1, L2)), PRED, OP, MACRO) // expands to (x, x) (x, y) (y, x) (y, y) (a, a) (a, b) (b, a) (b, b)
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)