The BOOST_PP_WHILE_d macro represents a reentry into the BOOST_PP_WHILE looping construct.

Usage

BOOST_PP_WHILE_ ## d(pred, op, state)

Arguments

d
The next available BOOST_PP_WHILE iteration.
pred
A binary predicate of the form pred(d, state).  This predicate is expanded by BOOST_PP_WHILE with the next available iteration d and the current state.  This predicate must expand to value in the range of 0 to BOOST_PP_LIMIT_MAG. The construct continues to loop until this predicate returns 0.  When this predicate returns 0, BOOST_PP_WHILE returns the current state.
op
A binary operation of the form op(d, state).  This operation is expanded by BOOST_PP_WHILE with the next available iteration d and the current state.  This macro is repeatedly applied to the state, each time producing a new state, until pred returns 0.
state
The initial state.  Often this argument is a tuple.

Remarks

This macro iterates op(d, state) while pred(d, state) is non-zero.  In other words expands to:
op(d, ... op(d, op(d, 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 d 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_WHILE_, d)(pred, op, state).
Previously, it was possible to concatenate d directly to BOOST_PP_WHILE (without the trailing underscore).  This is no longer supported.

See Also

Requirements

Header:  <boost/preprocessor/control/while.hpp>

Sample Code

#include <boost/preprocessor/arithmetic/add.hpp>
#include <boost/preprocessor/arithmetic/dec.hpp>
#include <boost/preprocessor/array/elem.hpp>
#include <boost/preprocessor/array/size.hpp>
#include <boost/preprocessor/control/while.hpp>
#include <boost/preprocessor/tuple/elem.hpp>

#define PRED(d, data) BOOST_PP_TUPLE_ELEM(3, 1, data)

#define OP(d, data) \
   OP_D( \
      d, \
      BOOST_PP_TUPLE_ELEM(3, 0, data), \
      BOOST_PP_TUPLE_ELEM(3, 1, data), \
      BOOST_PP_TUPLE_ELEM(3, 2, data) \
   ) \
   /**/

#define OP_D(d, res, i, array) \
   ( \
      BOOST_PP_ADD_D( \
         d, res, \
         BOOST_PP_ARRAY_ELEM(BOOST_PP_DEC(i), array)), \
      BOOST_PP_DEC(i), \
      array \
   ) \
   /**/

#define ACCUMULATE_D(d, array) \
   BOOST_PP_TUPLE_ELEM( \
      3, 0, \
      BOOST_PP_WHILE_ ## d( \
         PRED, OP, \
         (0, BOOST_PP_ARRAY_SIZE(array), array) \
      ) \
   ) \
   /**/

#define ARRAY (4, (1, 2, 3, 4))

ACCUMULATE_D(1, ARRAY)// expands to 10

Copyright Housemarque Oy 2002
Copyright Paul Mensonides 2002
Copyright Edward Diener 2014

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)