C++ Boost

Boost.Preprocessor

Header <boost/preprocessor/while.hpp>


Prev Next Macros Headers

#define BOOST_PP_WHILE(PRED,OP,STATE)

Iterates OP(D,STATE) while PRED(D,STATE) is true.

In other words, expands to:

OP(D, ... OP(D, OP(D,STATE) ) ... )

The depth of iteration is determined by PRED(D,STATE).

For example,

#define PRED(D,STATE) BOOST_PP_LESS_D(D,BOOST_PP_TUPLE_ELEM(2,0,STATE),BOOST_PP_TUPLE_ELEM(2,1,STATE))
#define OP(D,STATE) (BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(2,0,STATE)),BOOST_PP_TUPLE_ELEM(2,1,STATE))
BOOST_PP_WHILE(PRED,OP,(0,3))

expands to:

(3,3)

Legend

Automatic recursion?

BOOST_PP_WHILE() currently does not implement automatic recursion. The reason for this is that it would lead to very poor performance. The automatic recursion technique takes O(N) steps just to find out that the Nth recursion should be used. This would dramatically effect the time complexity of macros using automatic recursion.

Note

Example


Prev Next Macros Headers

Revised

© Copyright Housemarque Oy 2002

Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.