values.html 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <html>
  2. <head>
  3. <!-- Generated by the Spirit (http://spirit.sf.net) QuickDoc -->
  4. <title>Values</title>
  5. <link rel="stylesheet" href="theme/style.css" type="text/css">
  6. <link rel="prev" href="arguments.html">
  7. <link rel="next" href="variables.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>Values</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="arguments.html"><img src="theme/l_arr.gif" border="0"></a></td>
  25. <td width="20"><a href="variables.html"><img src="theme/r_arr.gif" border="0"></a></td>
  26. </tr>
  27. </table>
  28. <p>
  29. Whenever we see a constant in a curryable-function such as the plus above, an actor&lt;value&lt;T&gt; &gt; (where T is the type of the constant) is, by default, automatically created for us. For instance, the example plus above is actually equivalent to:</p>
  30. <code><pre>
  31. <span class=identifier>plus</span><span class=special>(</span><span class=identifier>arg1</span><span class=special>, </span><span class=identifier>actor</span><span class=special>&lt;</span><span class=identifier>value</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>&gt; &gt;(</span><span class=identifier>value</span><span class=special>&lt;</span><span class=keyword>int</span><span class=special>&gt;(</span><span class=number>6</span><span class=special>)))
  32. </span></pre></code>
  33. <p>
  34. A nifty shortcut is the val(v) utility function. The expression above is also equivalent to:</p>
  35. <code><pre>
  36. <span class=identifier>plus</span><span class=special>(</span><span class=identifier>arg1</span><span class=special>, </span><span class=identifier>val</span><span class=special>(</span><span class=number>6</span><span class=special>))
  37. </span></pre></code>
  38. <p>
  39. actor&lt;value&lt;int&gt; &gt;(value&lt;int&gt;(6)) is implicitly created behind the scenes, so there's really no need to explicitly type everything but:</p>
  40. <code><pre>
  41. <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>)
  42. </span></pre></code>
  43. <p>
  44. There are situations though, as we'll see later on, where we might want to explicily write val(x).</p>
  45. <p>
  46. Like arguments, values are also actors. As such, values can be evaluated through the actor's operator(). Such invocation gives the value's identity. Example:</p>
  47. <code><pre>
  48. <span class=identifier>cout </span><span class=special>&lt;&lt; </span><span class=identifier>val</span><span class=special>(</span><span class=number>3</span><span class=special>)() &lt;&lt; </span><span class=identifier>val</span><span class=special>(</span><span class=string>&quot;Hello World&quot;</span><span class=special>)();
  49. </span><span class=identifier>prints </span><span class=identifier>out </span><span class=string>&quot;3 Hello World&quot;</span><span class=special>.
  50. </span></pre></code>
  51. <table border="0">
  52. <tr>
  53. <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
  54. <td width="30"><a href="arguments.html"><img src="theme/l_arr.gif" border="0"></a></td>
  55. <td width="20"><a href="variables.html"><img src="theme/r_arr.gif" border="0"></a></td>
  56. </tr>
  57. </table>
  58. <br>
  59. <hr size="1">
  60. <p class="copyright">Copyright &copy; 2001-2002 Joel de Guzman<br>
  61. <br>
  62. <font size="2">Use, modification and distribution is subject to the Boost Software
  63. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  64. http://www.boost.org/LICENSE_1_0.txt) </font> </p>
  65. </body>
  66. </html>