The BOOST_PP_FOR_r macro represents a reentry into the BOOST_PP_FOR repetition construct.

#### Usage

BOOST_PP_FOR_ ## r(state, pred, op, macro)

#### Arguments

r
  The next available BOOST_PP_FOR repetition.
state
  The initial state.
pred
  A binary predicate of the form pred(r, state). This macro must expand to an integer in the range of 0 to BOOST_PP_LIMIT_MAG. BOOST_PP_FOR repeatedly expands macro while this predicate returns non-zero. This macro is called with the next available BOOST_PP_FOR repetition and the current state.
op
  A binary operation of the form op(r, state). This operation is expanded by BOOST_PP_FOR with the next available BOOST_PP_FOR repetition and the current state. This macro is repeatedly applied to the state, each time producing a new state, until pred returns 0.
macro
  A binary macro of the form macro(r, state). This macro is expanded by BOOST_PP_FOR with the next available BOOST_PP_FOR repetition and the current state. This macro is is repeated by BOOST_PP_FOR until pred returns 0.

#### Remarks

This macro expands to the sequence:
macro(r, state) macro(r, op(r, state)) ... macro(r, op(r, ... op(r, state) ... ))
At certain times, it may be necessary to perform the concatenation with BOOST_PP_CAT rather than the preprocessor token-pasting operator. This happens when the r value is a macro invocation itself. It needs a delay to allow it to expand. The syntax in such a scenario becomes:
BOOST_PP_CAT(BOOST_PP_FOR_, r)(state, pred, op, macro)

#### See Also

- BOOST_PP_CAT
- BOOST_PP_FOR
- BOOST_PP_LIMIT_MAG

#### Requirements

Header: <boost/preprocessor/repetition/for.hpp>

#### Sample Code

    #include <boost/preprocessor/arithmetic/dec.hpp>
    #include <boost/preprocessor/arithmetic/inc.hpp>
    #include <boost/preprocessor/comparison/not_equal.hpp>
    #include <boost/preprocessor/punctuation/comma_if.hpp>
    #include <boost/preprocessor/repetition/for.hpp>
    #include <boost/preprocessor/tuple/elem.hpp>

    #define PRED(r, state) \
       BOOST_PP_NOT_EQUAL( \
          BOOST_PP_TUPLE_ELEM(4, 0, state), \
          BOOST_PP_INC( \
             BOOST_PP_TUPLE_ELEM(4, 1, state) \
          ) \
       ) \
       /**/

    #define OP(r, state) \
       ( \
          BOOST_PP_INC( \
             BOOST_PP_TUPLE_ELEM(4, 0, state) \
          ), \
          BOOST_PP_TUPLE_ELEM(4, 1, state), \
          BOOST_PP_TUPLE_ELEM(4, 2, state), \
          BOOST_PP_INC( \
             BOOST_PP_TUPLE_ELEM(4, 3, state) \
          ) \
       ) \
       /**/

    #define MACRO(r, state) \
       BOOST_PP_COMMA_IF( \
          BOOST_PP_TUPLE_ELEM(4, 3, state) \
       ) template< \
          BOOST_PP_FOR_ ## r( \
             (0, BOOST_PP_TUPLE_ELEM(4, 0, state), _, 0), \
             PRED_2, OP, MACRO_2 \
          ) \
       > class BOOST_PP_CAT( \
          BOOST_PP_TUPLE_ELEM(4, 2, state), \
          BOOST_PP_TUPLE_ELEM(4, 0, state) \
       ) \
       /**/

    #define PRED_2(r, state) \
       BOOST_PP_NOT_EQUAL( \
          BOOST_PP_TUPLE_ELEM(4, 0, state), \
          BOOST_PP_TUPLE_ELEM(4, 1, state) \
       ) \
       /**/

    #define MACRO_2(r, state) \
       BOOST_PP_COMMA_IF( \
          BOOST_PP_TUPLE_ELEM(4, 0, state) \
       ) class \
       /**/

    #define TEMPLATE_TEMPLATE(low, high, name) \
       BOOST_PP_FOR( \
          (low, high, name, 0), \
          PRED, OP, MACRO \
       ) \
       /**/

    TEMPLATE_TEMPLATE(2, 4, T)
    /*
       expands to...
       template<class, class> class T2,
       template<class, class, class> class T3,
       template<class, class, class, class> class T4
    */