BOOST_PP_SUB_D

The BOOST_PP_SUB_D macro expands to the difference between its second and third arguments. It reenters BOOST_PP_WHILE with maximum efficiency.

#### Usage

BOOST_PP_SUB_D(d, x, y)

#### Arguments

d
  The next available BOOST_PP_WHILE iteration.
x
  The minuend of the operation. Valid values range from 0 to BOOST_PP_LIMIT_MAG.
y
  The subtrahend of the operation. Valid values range from 0 to BOOST_PP_LIMIT_MAG.

#### Remarks

If the difference between x and y is less than 0, the result is saturated to 0.

#### See Also

- BOOST_PP_LIMIT_MAG
- BOOST_PP_SUB

#### Requirements

Header: <boost/preprocessor/arithmetic/sub.hpp>

#### Sample Code

    #include <boost/preprocessor/arithmetic/dec.hpp>
    #include <boost/preprocessor/arithmetic/sub.hpp>
    #include <boost/preprocessor/control/while.hpp>
    #include <boost/preprocessor/tuple/elem.hpp>

    #define PRED(d, data) BOOST_PP_TUPLE_ELEM(2, 0, data)

    #define OP(d, data) \
       ( \
          BOOST_PP_DEC( \
             BOOST_PP_TUPLE_ELEM(2, 0, data) \
          ), \
          BOOST_PP_SUB_D( \
             d, \
             BOOST_PP_TUPLE_ELEM(2, 1, data), \
             2 \
          ) \
       ) \
       /**/

    // decrement 'x' by 2 'n' times
    #define STRIDE(x, n) BOOST_PP_TUPLE_ELEM(2, 1, BOOST_PP_WHILE(PRED, OP, (n, x)))

    STRIDE(10, 2) // expands to 6
    STRIDE(14, 6) // expands to 2

© Copyright Housemarque Oy 2002 © Copyright Paul Mensonides 2002

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)