Files
preprocessor/doc/reference/for.htm

85 lines
3.7 KiB
HTML
Raw Normal View History

2002-02-04 14:57:59 +00:00
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Boost.Preprocessor</title>
</head>
<body bgcolor="#FFFFFF" link="#0000ff" vlink="#800080">
<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>
<h2 align="center">Reference</h2>
</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-02-04 14:57:59 +00:00
<a href="expand.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
<h1>#include &lt;<a href="../../../../boost/preprocessor/for.hpp">boost/preprocessor/for.hpp</a>&gt;</h1>
2002-01-31 15:36:01 +00:00
<hr>
2002-02-04 14:57:59 +00:00
<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>
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-01-31 15:36:01 +00:00
I(R,X) I(R,F(R,X)) I(R,F(R,F(R,X))) ... I(R,F(R,F(...F(R,X)...)))
2002-02-04 14:57:59 +00:00
</pre>
<p>The length of the sequence is determined by <code>C(R,X)</code>.</p>
<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
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>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()
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
2002-02-04 14:57:59 +00:00
by the C++ preprocessor.</li>
</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-04 14:57:59 +00:00
<hr>
2002-01-31 15:36:01 +00:00
2002-02-04 14:57:59 +00:00
<a href="expand.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>&copy; Copyright <a href="http://www.housemarque.com">Housemarque Oy</a> 2002</i></p>
<p><i>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-02-04 14:57:59 +00:00
for any purpose.</i></p>
2002-01-31 15:36:01 +00:00
2002-02-04 14:57:59 +00:00
</body></html>