mirror of
https://github.com/boostorg/phoenix.git
synced 2026-02-14 13:02:10 +00:00
108 lines
6.2 KiB
HTML
108 lines
6.2 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>Statement</title>
|
|
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
|
|
<link rel="home" href="../../index.html" title="Chapter 1. Phoenix 3.0">
|
|
<link rel="up" href="../modules.html" title="Modules">
|
|
<link rel="prev" href="operator.html" title="Operator">
|
|
<link rel="next" href="statement/block_statement.html" title="Block Statement">
|
|
</head>
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
<table cellpadding="2" width="100%"><tr><td valign="top"></td></tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="operator.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../modules.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="statement/block_statement.html"><img src="../../images/next.png" alt="Next"></a>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="phoenix.modules.statement"></a><a class="link" href="statement.html" title="Statement">Statement</a>
|
|
</h3></div></div></div>
|
|
<div class="toc"><dl>
|
|
<dt><span class="section"><a href="statement/block_statement.html">Block Statement</a></span></dt>
|
|
<dt><span class="section"><a href="statement/if__statement.html">if_ Statement</a></span></dt>
|
|
<dt><span class="section"><a href="statement/___if_else_____statement.html">if_else_ Statement</a></span></dt>
|
|
<dt><span class="section"><a href="statement/switch__statement.html">switch_
|
|
Statement</a></span></dt>
|
|
<dt><span class="section"><a href="statement/while__statement.html">while_
|
|
Statement</a></span></dt>
|
|
<dt><span class="section"><a href="statement/___do_while_____statement.html">do_while_ Statement</a></span></dt>
|
|
<dt><span class="section"><a href="statement/for_statement.html">for_ Statement</a></span></dt>
|
|
<dt><span class="section"><a href="statement/try__catch__statement.html">try_
|
|
catch_ Statement</a></span></dt>
|
|
<dt><span class="section"><a href="statement/throw_.html">throw_</a></span></dt>
|
|
</dl></div>
|
|
<p>
|
|
<span class="bold"><strong><span class="emphasis"><em>Lazy statements...</em></span></strong></span>
|
|
</p>
|
|
<p>
|
|
The primitives and composite building blocks presented so far are sufficiently
|
|
powerful to construct quite elaborate structures. We have presented lazy-functions
|
|
and lazy-operators. How about lazy-statements? First, an appetizer:
|
|
</p>
|
|
<p>
|
|
Print all odd-numbered contents of an STL container using <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code>
|
|
(<a href="../../../../example/all_odds.cpp" target="_top">all_odds.cpp</a>):
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">c</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span>
|
|
<span class="identifier">if_</span><span class="special">(</span><span class="identifier">arg1</span> <span class="special">%</span> <span class="number">2</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span>
|
|
<span class="special">[</span>
|
|
<span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">arg1</span> <span class="special"><<</span> <span class="char">' '</span>
|
|
<span class="special">]</span>
|
|
<span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Huh? Is that valid C++? Read on...
|
|
</p>
|
|
<p>
|
|
Yes, it is valid C++. The sample code above is as close as you can get to
|
|
the syntax of C++. This stylized C++ syntax differs from actual C++ code.
|
|
First, the <code class="computeroutput"><span class="keyword">if</span></code> has a trailing
|
|
underscore. Second, the block uses square brackets instead of the familiar
|
|
curly braces {}.
|
|
</p>
|
|
<div class="note"><table border="0" summary="Note">
|
|
<tr>
|
|
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../images/note.png"></td>
|
|
<th align="left">Note</th>
|
|
</tr>
|
|
<tr><td align="left" valign="top">
|
|
<p>
|
|
<span class="bold"><strong>C++ in C++?</strong></span>
|
|
</p>
|
|
<p>
|
|
In as much as <a href="http://spirit.sourceforge.net" target="_top">Spirit</a>
|
|
attempts to mimic EBNF in C++, Phoenix attempts to mimic C++ in C++!!!
|
|
</p>
|
|
</td></tr>
|
|
</table></div>
|
|
<div class="note"><table border="0" summary="Note">
|
|
<tr>
|
|
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../images/note.png"></td>
|
|
<th align="left">Note</th>
|
|
</tr>
|
|
<tr><td align="left" valign="top"><p>
|
|
Unlike lazy functions and lazy operators, lazy statements always return
|
|
void.
|
|
</p></td></tr>
|
|
</table></div>
|
|
<p>
|
|
Here are more examples with annotations. The code almost speaks for itself.
|
|
</p>
|
|
</div>
|
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
|
<td align="left"></td>
|
|
<td align="right"><div class="copyright-footer">Copyright © 2002-2005, 2010 Joel de Guzman, Dan Marsden, Thomas Heller<p>
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
|
</p>
|
|
</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="operator.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../modules.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="statement/block_statement.html"><img src="../../images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|