This macro is intended to avoid the use of
automatic-recursion at deep expansion depths.
Automatic-recursion at such depths can be inefficient on some preprocessors.
It is not intended to be used directly with the invocation of macros with a
_D suffix such as:
BOOST_PP_ADD_D(BOOST_PP_DEDUCE_D(), x, y)
If it is used in this context, the
_D macro will fail.
The
_D macros directly concatenate to the
d parameter that is passed to them,
which would prevent
BOOST_PP_DEDUCE_D() from expanding.
Furthermore, it is pointless to use this macro in a situation such as this
because it would already be too late to gain any efficiency.
#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