2002-02-04 14:57:59 +00:00
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=iso-8859-1" >
2002-05-16 22:17:39 +00:00
< link rel = "stylesheet" type = "text/css" href = "../../../../boost.css" >
2002-02-05 12:13:37 +00:00
< title > Boost.Preprocessor - Reference< / title >
2002-02-04 14:57:59 +00:00
< / head >
2002-05-16 22:17:39 +00:00
< body link = "#0000ff" vlink = "#800080" >
2002-02-04 14:57:59 +00:00
< table border = "0" cellpadding = "7" cellspacing = "0" width = "100%" summary =
"header">
< tr >
< td valign = "top" width = "300" >
< h3 > < a href = "../../../../index.htm" > < img height = "86" width = "277" alt = "C++ Boost" src = "../../../../c++boost.gif" border = "0" > < / a > < / h3 >
< / td >
< td valign = "top" >
< h1 align = "center" > Boost.Preprocessor< / h1 >
2002-05-17 21:24:59 +00:00
< h2 align = "center" > Header < < a href = "../../../../boost/preprocessor/for.hpp" > boost/preprocessor/for.hpp< / a > > < / h2 >
2002-02-04 14:57:59 +00:00
< / td >
< / tr >
< / table >
2002-01-31 15:36:01 +00:00
2002-02-04 14:57:59 +00:00
< hr >
2002-01-31 15:36:01 +00:00
2002-03-11 16:11:34 +00:00
< a href = "expr_if.htm" > Prev< / a > < a href = "identity.htm" > Next< / a > < a href = "index.htm#Macros" > Macros< / a > < a href = "index.htm#Headers" > Headers< / a >
2002-01-31 15:36:01 +00:00
< hr >
2002-05-16 22:17:39 +00:00
< h3 > < a name = "BOOST_PP_FOR" > #define BOOST_PP_FOR< / a > (STATE,PRED,OP,MACRO)< / h3 >
2002-04-12 11:26:25 +00:00
< p > Repeats < code > MACRO(R,STATE)< / code > and iterates < code > OP(R,STATE)< / code > while
< code > PRED(R,STATE)< / code > is true.< / p >
2002-01-31 15:36:01 +00:00
2002-02-04 14:57:59 +00:00
< p > In other words, expands to the sequence:< / p >
2002-01-31 15:36:01 +00:00
2002-02-04 14:57:59 +00:00
< pre >
2002-04-13 11:14:50 +00:00
MACRO(R,STATE)
MACRO(R,OP(R,STATE))
MACRO(R,OP(R,OP(R,STATE)))
...
MACRO(R,OP(R,OP(...OP(R,STATE)...)))
2002-02-04 14:57:59 +00:00
< / pre >
2002-04-12 11:26:25 +00:00
< p > The length of the sequence is determined by < code > PRED(R,STATE)< / code > .< / p >
2002-02-04 14:57:59 +00:00
2002-03-10 12:31:37 +00:00
< p > For example,< / p >
< pre >
2002-04-12 11:26:25 +00:00
#define PRED(R,STATE) < a href = "comparison_less.htm#BOOST_PP_LESS" > BOOST_PP_LESS< / a > (< a href = "tuple_elem.htm#BOOST_PP_TUPLE_ELEM" > BOOST_PP_TUPLE_ELEM< / a > (2,0,STATE),< a href = "tuple_elem.htm#BOOST_PP_TUPLE_ELEM" > BOOST_PP_TUPLE_ELEM< / a > (2,1,STATE))
#define OP(R,STATE) (< a href = "inc.htm#BOOST_PP_INC" > BOOST_PP_INC< / a > (< a href = "tuple_elem.htm#BOOST_PP_TUPLE_ELEM" > BOOST_PP_TUPLE_ELEM< / a > (2,0,STATE)),< a href = "tuple_elem.htm#BOOST_PP_TUPLE_ELEM" > BOOST_PP_TUPLE_ELEM< / a > (2,1,STATE))
#define MACRO(R,STATE) < a href = "tuple_elem.htm#BOOST_PP_TUPLE_ELEM" > BOOST_PP_TUPLE_ELEM< / a > (2,0,STATE)
< a href = "for.htm#BOOST_PP_FOR" > BOOST_PP_FOR< / a > ((0,3),PRED,OP,MACRO)
2002-03-10 12:31:37 +00:00
< / pre >
< p > expands to:< / p >
< pre >
0 1 2
< / pre >
2002-02-04 14:57:59 +00:00
< h3 > Legend< / h3 >
< ul >
2002-04-12 11:26:25 +00:00
< li > < b > STATE< / b > is the current state of iteration. The state is usually a tuple.< / li >
< li > < b > PRED< / b > is the condition for iteration. It must expand to a decimal
2002-02-04 14:57:59 +00:00
integer literal.< / li >
2002-04-12 11:26:25 +00:00
< li > < b > OP< / b > is the iterated macro. Note that if the state is a tuple, then
OP(R,STATE) usually expands to a tuple of the same number of elements.< / li >
< li > < b > MACRO< / b > is the state instantiation macro.< / li >
2002-02-04 14:57:59 +00:00
< li > < b > R< / b > is the recursion depth and should only be used as a parameter to
2002-01-31 15:36:01 +00:00
other macros using < a href = "for.htm#BOOST_PP_FOR" > BOOST_PP_FOR< / a > () or for invoking < a href = "for.htm#BOOST_PP_FOR" > BOOST_PP_FOR< / a > ##R()
2002-04-12 11:26:25 +00:00
directly. For each macro using < a href = "for.htm#BOOST_PP_FOR" > BOOST_PP_FOR< / a > (), e.g. < a href = "list_for_each.htm#BOOST_PP_LIST_FOR_EACH" > BOOST_PP_LIST_FOR_EACH< / a > (),
there is a version of the macro, e.g. < a href = "list_for_each.htm#BOOST_PP_LIST_FOR_EACH_R" > BOOST_PP_LIST_FOR_EACH_R< / a > (), distinguished
by the R suffix, that accepts an additional recursion depth as the first
parameter. This technique is necessary to avoid recursively expanding the same
macro again, which is not permitted by the C++ preprocessor.< / li >
2002-02-04 14:57:59 +00:00
< / ul >
2002-01-31 15:36:01 +00:00
2002-02-04 14:57:59 +00:00
< h3 > < a href = "repeat.htm#BOOST_PP_REPEAT" > BOOST_PP_REPEAT< / a > () vs < a href = "for.htm#BOOST_PP_FOR" > BOOST_PP_FOR< / a > ()< / h3 >
2002-01-31 15:36:01 +00:00
2002-02-04 14:57:59 +00:00
< p > < a href = "for.htm#BOOST_PP_FOR" > BOOST_PP_FOR< / a > () is a generalization of < a href = "repeat.htm#BOOST_PP_REPEAT" > BOOST_PP_REPEAT< / a > (). This means that
2002-01-31 21:52:46 +00:00
< a href = "repeat.htm#BOOST_PP_REPEAT" > BOOST_PP_REPEAT< / a > () can be implemented using < a href = "for.htm#BOOST_PP_FOR" > BOOST_PP_FOR< / a > (). However,
2002-01-31 15:36:01 +00:00
< a href = "repeat.htm#BOOST_PP_REPEAT" > BOOST_PP_REPEAT< / a > () was introduced earlier, is generally easier to use, and is
2002-02-04 14:57:59 +00:00
still quite useful on its own.< / p >
< h3 > 2D and 3D repetition< / h3 >
2002-01-31 15:36:01 +00:00
2002-02-04 14:57:59 +00:00
< p > < a href = "for.htm#BOOST_PP_FOR" > BOOST_PP_FOR< / a > () can be used for multidimensional repetition simply by
invoking < a href = "for.htm#BOOST_PP_FOR" > BOOST_PP_FOR< / a > ##R() directly.< / p >
2002-01-31 15:36:01 +00:00
2002-02-05 12:16:25 +00:00
< h3 > Test< / h3 >
< ul >
< li > < a href = "../../test/for_test.cpp" > for_test.cpp< / a > < / li >
< / ul >
2002-02-04 14:57:59 +00:00
< hr >
2002-01-31 15:36:01 +00:00
2002-03-11 16:11:34 +00:00
< a href = "expr_if.htm" > Prev< / a > < a href = "identity.htm" > Next< / a > < a href = "index.htm#Macros" > Macros< / a > < a href = "index.htm#Headers" > Headers< / a >
2002-01-31 15:36:01 +00:00
< hr >
2002-02-04 14:57:59 +00:00
< p > Revised <!-- webbot bot="Timestamp" s - type="EDITED" s - format="%d %b %Y" startspan --> <!-- webbot bot="Timestamp" endspan i - checksum="15246" --> < / p >
2002-01-31 15:36:01 +00:00
2002-02-04 14:57:59 +00:00
< p > < i > © Copyright < a href = "http://www.housemarque.com" > Housemarque Oy< / a > 2002< / i > < / p >
2002-05-16 22:17:39 +00:00
< p > Permission to copy, use, modify, sell and distribute this document is granted
2002-01-31 15:36:01 +00:00
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
2002-05-16 22:17:39 +00:00
for any purpose.< / p >
2002-01-31 15:36:01 +00:00
2002-02-04 14:57:59 +00:00
< / body > < / html >