The BOOST_PP_MOD_D macro expands to the modulus of its second and third arguments.  It reenters BOOST_PP_WHILE with maximum efficiency.

Usage

BOOST_PP_MOD_D(d, x, y)

Arguments

d
The next available BOOST_PP_WHILE iteration. 
x
The dividend (numerator) of the operation.  Valid values range from 0 to BOOST_PP_LIMIT_MAG.
y
The divisor (denominator) of the operation.  Valid values range from 1 to BOOST_PP_LIMIT_MAG.

Remarks

If y is 0, the result is undefined.

See Also

Requirements

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

Sample Code

#include <boost/preprocessor/arithmetic/mod.hpp>
#include <boost/preprocessor/list/filter.hpp>
#include <boost/preprocessor/logical/not.hpp>

#define LIST (1, (2, (3, (4, (5, BOOST_PP_NIL)))))

#define EVEN_P(d, _, num) BOOST_PP_NOT(BOOST_PP_MOD_D(d, num, 2))
#define EVEN(list) BOOST_PP_LIST_FILTER(EVEN_P, nil, list)

EVEN(LIST) // expands to (2, (4, BOOST_PP_NIL))

#define ODD_P(d, _, num) BOOST_PP_MOD_D(d, num, 2)
#define ODD(list) BOOST_PP_LIST_FILTER(ODD_P, nil, list)

ODD(LIST) // expands to (1, (3, (5, BOOST_PP_NIL)))

© 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)