The BOOST_PP_LIST_FILTER_D macro filters a list according to a supplied criterion.  It reenters BOOST_PP_WHILE with maximum efficiency.

Usage

BOOST_PP_LIST_FILTER_D(d, pred, data, list)

Arguments

d
The next available BOOST_PP_WHILE iteration.
pred
A ternary predicate of the form pred(d, data, elem).  This predicate is expanded by BOOST_PP_LIST_FILTER for each element in list with the next available BOOST_PP_WHILE iteration, the auxiliary data, and the current element in list.  This macro must return a integral value in the range of 0 to BOOST_PP_LIMIT_MAG.  If this predicate expands to non-zero for a certain element, that element is included in the resulting list.
data
Auxiliary data passed to pred.
list
The list to be filtered.

Remarks

This macro expands pred for each element in list.  It builds a new list out of each element for which pred returns non-zero.

See Also

Requirements

Header:  <boost/preprocessor/list/filter.hpp>

Sample Code

#include <boost/preprocessor/comparison/less_equal.hpp>
#include <boost/preprocessor/list/filter.hpp>
#include <boost/preprocessor/list/fold_right.hpp>

#define A (1, (2, (3, (4, BOOST_PP_NIL))))
#define B (A, (A, (A, (A, BOOST_PP_NIL))))

#define PRED(d, data, x) BOOST_PP_LESS_EQUAL(x, data)
#define OP(d, state, x) (BOOST_PP_LIST_FILTER_D(d, PRED, 2, x), state)

BOOST_PP_LIST_FOLD_RIGHT(OP, BOOST_PP_NIL, B)
/*
   expands to:
   ((1, (2, BOOST_PP_NIL)), 
   ((1, (2, BOOST_PP_NIL)), 
   ((1, (2, BOOST_PP_NIL)), 
   ((1, (2, BOOST_PP_NIL)), 
      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)