summaryrefslogtreecommitdiff
path: root/libs/phoenix/doc/html/phoenix/modules/statement.html
blob: 2d4a451ce84039135df0077771b87331892b2501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Statement</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../../index.html" title="Chapter&#160;1.&#160;Phoenix 3.0.5">
<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"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="operator.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../modules.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="statement/block_statement.html"><img src="../../../../../../doc/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 class="toc">
<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 expressions 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">&lt;&lt;</span> <span class="identifier">arg1</span> <span class="special">&lt;&lt;</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="../../../../../../doc/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="../../../../../../doc/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 &#169; 2002-2005, 2010, 2014 Joel de Guzman, Dan Marsden, Thomas Heller, John
      Fletcher<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="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../modules.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="statement/block_statement.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>