#include <boost/preprocessor/arithmetic/add.hpp> #include <boost/preprocessor/arithmetic/inc.hpp> #include <boost/preprocessor/arithmetic/sub.hpp> #include <boost/preprocessor/control/deduce_d.hpp> #include <boost/preprocessor/punctuation/comma_if.hpp> #include <boost/preprocessor/repetition/repeat.hpp> #include <boost/preprocessor/tuple/elem.hpp> #define RANGE(first, last) \ BOOST_PP_REPEAT( \ BOOST_PP_INC( \ BOOST_PP_SUB(last, first) \ ), \ RANGE_M, \ (first, BOOST_PP_DEDUCE_D()) \ ) \ /**/ #define RANGE_M(z, n, data) \ RANGE_M_2( \ n, \ BOOST_PP_TUPLE_ELEM(2, 0, data), \ BOOST_PP_TUPLE_ELEM(2, 1, data) \ ) \ /**/ #define RANGE_M_2(n, first, d) \ BOOST_PP_COMMA_IF(n) BOOST_PP_ADD_D(d, n, first) \ /**/ RANGE(5, 10) // expands to 5, 6, 7, 8, 9, 10
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)