Files
preprocessor/doc/reference/while.htm

100 lines
4.3 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">
2002-05-16 22:17:39 +00:00
<link rel="stylesheet" type="text/css" href="../../../../boost.css">
2002-02-05 12:16:25 +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 &lt;<a href="../../../../boost/preprocessor/while.hpp">boost/preprocessor/while.hpp</a>&gt;</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-02-04 14:57:59 +00:00
<a href="tuple_to_list.htm">Prev</a> <a href="arithmetic.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_WHILE">#define BOOST_PP_WHILE</a>(PRED,OP,STATE)</h3>
<p>Iterates <code>OP(D,STATE)</code> while <code>PRED(D,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:</p>
2002-01-31 15:36:01 +00:00
2002-02-04 14:57:59 +00:00
<pre>
OP(D, ... OP(D, OP(D,STATE) ) ... )
2002-02-04 14:57:59 +00:00
</pre>
<p>The depth of iteration is determined by <code>PRED(D,STATE)</code>.</p>
2002-02-04 14:57:59 +00:00
2002-03-10 12:31:37 +00:00
<p>For example,</p>
<pre>
#define PRED(D,STATE) <a href="comparison_less.htm#BOOST_PP_LESS_D">BOOST_PP_LESS_D</a>(D,<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(D,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))
<a href="while.htm#BOOST_PP_WHILE">BOOST_PP_WHILE</a>(PRED,OP,(0,3))
2002-03-10 12:31:37 +00:00
</pre>
<p>expands to:</p>
<pre>
(3,3)
</pre>
2002-02-04 14:57:59 +00:00
<h3>Legend</h3>
<ul>
<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>
<li><b>OP</b> is the iterated macro. Note that if the state is a tuple, then
OP(D,STATE) usually expands to a tuple of the same number of elements.</li>
2002-02-04 14:57:59 +00:00
<li><b>D</b> is the recursion depth and should only be used as a parameter
2002-01-31 15:36:01 +00:00
to other macros using <a href="while.htm#BOOST_PP_WHILE">BOOST_PP_WHILE</a>(). Such macros include
<a href="arithmetic_add.htm#BOOST_PP_ADD">BOOST_PP_ADD</a>() and other arithmetic operations. For each macro using
<a href="while.htm#BOOST_PP_WHILE">BOOST_PP_WHILE</a>(), there is a version of the macro, distinguished by the
D suffix (e.g. <a href="arithmetic_add.htm#BOOST_PP_ADD_D">BOOST_PP_ADD_D</a>()), that accepts an additional recursion
2002-01-31 15:36:01 +00:00
depth as the first parameter. This technique is necessary to avoid
recursively expanding the same macro again, which is not permitted by the
2002-02-04 14:57:59 +00:00
C++ preprocessor.</li>
</ul>
<h3>Note</h3>
<ul>
<li>The value of the D parameter may exceed <a href="limits.htm#BOOST_PP_LIMIT_MAG">BOOST_PP_LIMIT_MAG</a>.</li>
<li>Using <a href="while.htm#BOOST_PP_WHILE">BOOST_PP_WHILE</a>() is a bit tricky. This is due to the C++
preprocessor limitations. It is recommended to take a look at the
implementations of the various PREPROCESSOR library primitives such as
<a href="arithmetic_add.htm#BOOST_PP_ADD">BOOST_PP_ADD</a>() for additional examples.</li>
</ul>
<h3>Example</h3>
<ul>
<li><a href="../../example/count_down.c">count_down.c</a></li>
<li><a href="../../example/linear_fib.c">linear_fib.c</a></li>
<li><a href="../../example/delay.c">delay.c</a></li>
</ul>
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="tuple_to_list.htm">Prev</a> <a href="arithmetic.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>
<p><i>&copy; Copyright <a href="http://www.housemarque.com">Housemarque Oy</a> 2002</i></p>
2002-01-31 15:36:01 +00:00
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>