forked from boostorg/preprocessor
Longer macro parameter names
[SVN r13459]
This commit is contained in:
@ -26,25 +26,25 @@
|
||||
|
||||
<hr>
|
||||
|
||||
<h2><a name="BOOST_PP_FOR">#define BOOST_PP_FOR</a>(X,C,F,I)</h2>
|
||||
<p>Repeats <code>I(R,X)</code> and iterates <code>F(R,X)</code> while
|
||||
<code>C(R,X)</code> is true.</p>
|
||||
<h2><a name="BOOST_PP_FOR">#define BOOST_PP_FOR</a>(STATE,PRED,OP,MACRO)</h2>
|
||||
<p>Repeats <code>MACRO(R,STATE)</code> and iterates <code>OP(R,STATE)</code> while
|
||||
<code>PRED(R,STATE)</code> is true.</p>
|
||||
|
||||
<p>In other words, expands to the sequence:</p>
|
||||
|
||||
<pre>
|
||||
I(R,X) I(R,F(R,X)) I(R,F(R,F(R,X))) ... I(R,F(R,F(...F(R,X)...)))
|
||||
MACRO(R,STATE) MACRO(R,OP(R,STATE)) MACRO(R,OP(R,OP(R,STATE))) ... MACRO(R,OP(R,OP(...OP(R,STATE)...)))
|
||||
</pre>
|
||||
|
||||
<p>The length of the sequence is determined by <code>C(R,X)</code>.</p>
|
||||
<p>The length of the sequence is determined by <code>PRED(R,STATE)</code>.</p>
|
||||
|
||||
<p>For example,</p>
|
||||
|
||||
<pre>
|
||||
#define C(R,X) <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,X),<a href="tuple_elem.htm#BOOST_PP_TUPLE_ELEM">BOOST_PP_TUPLE_ELEM</a>(2,1,X))
|
||||
#define F(R,X) (<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,X)),<a href="tuple_elem.htm#BOOST_PP_TUPLE_ELEM">BOOST_PP_TUPLE_ELEM</a>(2,1,X))
|
||||
#define I(R,X) <a href="tuple_elem.htm#BOOST_PP_TUPLE_ELEM">BOOST_PP_TUPLE_ELEM</a>(2,0,X)
|
||||
<a href="for.htm#BOOST_PP_FOR">BOOST_PP_FOR</a>((0,3),C,F,I)
|
||||
#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)
|
||||
</pre>
|
||||
|
||||
<p>expands to:</p>
|
||||
@ -55,19 +55,19 @@
|
||||
|
||||
<h3>Legend</h3>
|
||||
<ul>
|
||||
<li><b>X</b> is the current state of iteration. The state is usually a tuple.</li>
|
||||
<li><b>C</b> is the condition for iteration. It must expand to a decimal
|
||||
<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
|
||||
integer literal.</li>
|
||||
<li><b>F</b> is the iterated macro. Note that if the state is a tuple, then
|
||||
F(R,X) usually expands to a tuple of the same number of elements.</li>
|
||||
<li><b>I</b> is the state instantiation macro.</li>
|
||||
<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>
|
||||
<li><b>R</b> is the recursion depth and should only be used as a parameter to
|
||||
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()
|
||||
directly. For each macro using <a href="for.htm#BOOST_PP_FOR">BOOST_PP_FOR</a>(), there is a version of the
|
||||
macro, 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>
|
||||
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>
|
||||
</ul>
|
||||
|
||||
<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>
|
||||
|
Reference in New Issue
Block a user