Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/spirit/phoenix/doc/arguments.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 7.9 KB
Line 
1<html>
2<head>
3<!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
4<title>Arguments</title>
5<link rel="stylesheet" href="theme/style.css" type="text/css">
6<link rel="prev" href="primitives.html">
7<link rel="next" href="values.html">
8</head>
9<body>
10<table width="100%" height="48" border="0" background="theme/bkd2.gif" cellspacing="2">
11  <tr>
12    <td width="10">
13    </td>
14    <td width="85%">
15      <font size="6" face="Verdana, Arial, Helvetica, sans-serif"><b>Arguments</b></font>
16    </td>
17    <td width="112"><a href="http://spirit.sf.net"><img src="theme/spirit.gif" align="right" border="0"></a></td>
18  </tr>
19</table>
20<br>
21<table border="0">
22  <tr>
23    <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
24    <td width="30"><a href="primitives.html"><img src="theme/l_arr.gif" border="0"></a></td>
25    <td width="20"><a href="values.html"><img src="theme/r_arr.gif" border="0"></a></td>
26   </tr>
27</table>
28<p>
29The most basic primitive is the argument placeholder. For the sake of explanation, we used the '?' in our introductory examples to represent unknown arguments or argument place holders. Later on, we introduced the notion of positional argument place holders.</p>
30<p>
31We use an object of a special class argument&lt;N&gt; to represent the Nth function argument. The argument placeholder acts as an imaginary data-bin where a function argument will be placed.</p>
32<p>
33There are a couple of predefined instances of argument&lt;N&gt; named arg1..argN (where N is a predefined maximum). When appropriate, we can of course define our own argument&lt;N&gt; names. For example:</p>
34<code><pre>
35    <span class=identifier>actor</span><span class=special>&lt;</span><span class=identifier>argument</span><span class=special>&lt;</span><span class=number>0</span><span class=special>&gt; &gt; </span><span class=identifier>first_param</span><span class=special>;    // </span><span class=identifier>note </span><span class=identifier>zero </span><span class=identifier>based </span><span class=identifier>index
36</span></pre></code>
37<p>
38Take note that it should be wrapped inside an actor to be useful. first_param can now be used as a parameter to a lazy function:</p>
39<code><pre>
40    <span class=identifier>plus</span><span class=special>(</span><span class=identifier>first_param</span><span class=special>, </span><span class=number>6</span><span class=special>)
41</span></pre></code>
42<p>
43which is equivalent to:</p>
44<code><pre>
45    <span class=identifier>plus</span><span class=special>(</span><span class=identifier>arg1</span><span class=special>, </span><span class=number>6</span><span class=special>)
46</span></pre></code>
47<p>
48Here are some sample preset definitions of arg1..N</p>
49<code><pre>
50    <span class=identifier>actor</span><span class=special>&lt;</span><span class=identifier>argument</span><span class=special>&lt;</span><span class=number>0</span><span class=special>&gt; &gt; </span><span class=keyword>const </span><span class=identifier>arg1 </span><span class=special>= </span><span class=identifier>argument</span><span class=special>&lt;</span><span class=number>0</span><span class=special>&gt;();
51    </span><span class=identifier>actor</span><span class=special>&lt;</span><span class=identifier>argument</span><span class=special>&lt;</span><span class=number>1</span><span class=special>&gt; &gt; </span><span class=keyword>const </span><span class=identifier>arg2 </span><span class=special>= </span><span class=identifier>argument</span><span class=special>&lt;</span><span class=number>1</span><span class=special>&gt;();
52    </span><span class=identifier>actor</span><span class=special>&lt;</span><span class=identifier>argument</span><span class=special>&lt;</span><span class=number>2</span><span class=special>&gt; &gt; </span><span class=keyword>const </span><span class=identifier>arg3 </span><span class=special>= </span><span class=identifier>argument</span><span class=special>&lt;</span><span class=number>2</span><span class=special>&gt;();
53    ...
54    </span><span class=identifier>actor</span><span class=special>&lt;</span><span class=identifier>argument</span><span class=special>&lt;</span><span class=identifier>N</span><span class=special>&gt; &gt; </span><span class=keyword>const </span><span class=identifier>argN </span><span class=special>= </span><span class=identifier>argument</span><span class=special>&lt;</span><span class=identifier>N</span><span class=special>&gt;();
55</span></pre></code>
56<p>
57An argument is in itself an actor base class. As such, arguments can be evaluated through the actor's operator(). An argument as an actor base class selects the Nth argument from the arguments passed in by the client (see actor).</p>
58<p>
59For example:</p>
60<code><pre>
61    <span class=keyword>char        </span><span class=identifier>c </span><span class=special>= </span><span class=literal>'A'</span><span class=special>;
62    </span><span class=keyword>int         </span><span class=identifier>i </span><span class=special>= </span><span class=number>123</span><span class=special>;
63    </span><span class=keyword>const </span><span class=keyword>char</span><span class=special>* </span><span class=identifier>s </span><span class=special>= </span><span class=string>&quot;Hello World&quot;</span><span class=special>;
64
65    </span><span class=identifier>cout </span><span class=special>&lt;&lt; </span><span class=identifier>arg1</span><span class=special>(</span><span class=identifier>c</span><span class=special>) &lt;&lt; </span><span class=literal>' '</span><span class=special>;     //  </span><span class=identifier>Get </span><span class=identifier>the </span><span class=number>1</span><span class=identifier>st </span><span class=identifier>argument </span><span class=identifier>of </span><span class=identifier>unnamed_f</span><span class=special>(</span><span class=identifier>c</span><span class=special>)
66    </span><span class=identifier>cout </span><span class=special>&lt;&lt; </span><span class=identifier>arg1</span><span class=special>(</span><span class=identifier>i</span><span class=special>, </span><span class=identifier>s</span><span class=special>) &lt;&lt; </span><span class=literal>' '</span><span class=special>;  //  </span><span class=identifier>Get </span><span class=identifier>the </span><span class=number>1</span><span class=identifier>st </span><span class=identifier>argument </span><span class=identifier>of </span><span class=identifier>unnamed_f</span><span class=special>(</span><span class=identifier>i</span><span class=special>, </span><span class=identifier>s</span><span class=special>)
67    </span><span class=identifier>cout </span><span class=special>&lt;&lt; </span><span class=identifier>arg2</span><span class=special>(</span><span class=identifier>i</span><span class=special>, </span><span class=identifier>s</span><span class=special>) &lt;&lt; </span><span class=literal>' '</span><span class=special>;  //  </span><span class=identifier>Get </span><span class=identifier>the </span><span class=number>2</span><span class=identifier>nd </span><span class=identifier>argument </span><span class=identifier>of </span><span class=identifier>unnamed_f</span><span class=special>(</span><span class=identifier>i</span><span class=special>, </span><span class=identifier>s</span><span class=special>)
68</span></pre></code>
69<p>
70will print out &quot;A 123 Hello World&quot;</p>
71<table border="0">
72  <tr>
73    <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
74    <td width="30"><a href="primitives.html"><img src="theme/l_arr.gif" border="0"></a></td>
75    <td width="20"><a href="values.html"><img src="theme/r_arr.gif" border="0"></a></td>
76   </tr>
77</table>
78<br>
79<hr size="1">
80<p class="copyright">Copyright &copy; 2001-2002 Joel de Guzman<br>
81  <br>
82<font size="2">Use, modification and distribution is subject to the Boost Software
83    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
84    http://www.boost.org/LICENSE_1_0.txt) </font> </p>
85</body>
86</html>
Note: See TracBrowser for help on using the repository browser.