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> |
---|
29 | The 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> |
---|
31 | We use an object of a special class argument<N> 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> |
---|
33 | There are a couple of predefined instances of argument<N> named arg1..argN (where N is a predefined maximum). When appropriate, we can of course define our own argument<N> names. For example:</p> |
---|
34 | <code><pre> |
---|
35 | <span class=identifier>actor</span><span class=special><</span><span class=identifier>argument</span><span class=special><</span><span class=number>0</span><span class=special>> > </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> |
---|
38 | Take 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> |
---|
43 | which 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> |
---|
48 | Here are some sample preset definitions of arg1..N</p> |
---|
49 | <code><pre> |
---|
50 | <span class=identifier>actor</span><span class=special><</span><span class=identifier>argument</span><span class=special><</span><span class=number>0</span><span class=special>> > </span><span class=keyword>const </span><span class=identifier>arg1 </span><span class=special>= </span><span class=identifier>argument</span><span class=special><</span><span class=number>0</span><span class=special>>(); |
---|
51 | </span><span class=identifier>actor</span><span class=special><</span><span class=identifier>argument</span><span class=special><</span><span class=number>1</span><span class=special>> > </span><span class=keyword>const </span><span class=identifier>arg2 </span><span class=special>= </span><span class=identifier>argument</span><span class=special><</span><span class=number>1</span><span class=special>>(); |
---|
52 | </span><span class=identifier>actor</span><span class=special><</span><span class=identifier>argument</span><span class=special><</span><span class=number>2</span><span class=special>> > </span><span class=keyword>const </span><span class=identifier>arg3 </span><span class=special>= </span><span class=identifier>argument</span><span class=special><</span><span class=number>2</span><span class=special>>(); |
---|
53 | ... |
---|
54 | </span><span class=identifier>actor</span><span class=special><</span><span class=identifier>argument</span><span class=special><</span><span class=identifier>N</span><span class=special>> > </span><span class=keyword>const </span><span class=identifier>argN </span><span class=special>= </span><span class=identifier>argument</span><span class=special><</span><span class=identifier>N</span><span class=special>>(); |
---|
55 | </span></pre></code> |
---|
56 | <p> |
---|
57 | An 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> |
---|
59 | For 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>"Hello World"</span><span class=special>; |
---|
64 | |
---|
65 | </span><span class=identifier>cout </span><span class=special><< </span><span class=identifier>arg1</span><span class=special>(</span><span class=identifier>c</span><span class=special>) << </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><< </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>) << </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><< </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>) << </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> |
---|
70 | will print out "A 123 Hello World"</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 © 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> |
---|