| [29] | 1 | <html> | 
|---|
|  | 2 | <head> | 
|---|
|  | 3 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | 
|---|
|  | 4 | <title>Chapter 8. Boost.Lambda</title> | 
|---|
|  | 5 | <link rel="stylesheet" href="boostbook.css" type="text/css"> | 
|---|
|  | 6 | <meta name="generator" content="DocBook XSL Stylesheets V1.68.1"> | 
|---|
|  | 7 | <link rel="start" href="index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> | 
|---|
|  | 8 | <link rel="up" href="libraries.html" title="Part I. The Boost C++ Libraries (BoostBook Subset)"> | 
|---|
|  | 9 | <link rel="prev" href="hash/acknowledgements.html" title=" Acknowledgements"> | 
|---|
|  | 10 | <link rel="next" href="lambda/getting_started.html" title="Getting Started"> | 
|---|
|  | 11 | </head> | 
|---|
|  | 12 | <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> | 
|---|
|  | 13 | <table cellpadding="2" width="100%"> | 
|---|
|  | 14 | <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../boost.png"></td> | 
|---|
|  | 15 | <td align="center"><a href="../../index.htm">Home</a></td> | 
|---|
|  | 16 | <td align="center"><a href="../../libs/libraries.htm">Libraries</a></td> | 
|---|
|  | 17 | <td align="center"><a href="../../people/people.htm">People</a></td> | 
|---|
|  | 18 | <td align="center"><a href="../../more/faq.htm">FAQ</a></td> | 
|---|
|  | 19 | <td align="center"><a href="../../more/index.htm">More</a></td> | 
|---|
|  | 20 | </table> | 
|---|
|  | 21 | <hr> | 
|---|
|  | 22 | <div class="spirit-nav"> | 
|---|
|  | 23 | <a accesskey="p" href="hash/acknowledgements.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.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="lambda/getting_started.html"><img src="images/next.png" alt="Next"></a> | 
|---|
|  | 24 | </div> | 
|---|
|  | 25 | <div class="chapter" lang="en"> | 
|---|
|  | 26 | <div class="titlepage"><div> | 
|---|
|  | 27 | <div><h2 class="title"> | 
|---|
|  | 28 | <a name="lambda"></a>Chapter 8. Boost.Lambda</h2></div> | 
|---|
|  | 29 | <div><div class="author"> | 
|---|
|  | 30 | <h3 class="author"> | 
|---|
|  | 31 | <span class="firstname">Jaakko</span> <span class="surname">Järvi</span> | 
|---|
|  | 32 | </h3> | 
|---|
|  | 33 | <code class="email"><<a href="mailto:jarvi%20at%20cs%20tamu%20edu">jarvi at cs tamu edu</a>></code> | 
|---|
|  | 34 | </div></div> | 
|---|
|  | 35 | <div><p class="copyright">Copyright © 1999-2004 Jaakko Järvi, Gary Powell</p></div> | 
|---|
|  | 36 | <div><div class="legalnotice"> | 
|---|
|  | 37 | <a name="id1242857"></a><p>Use, modification and distribution is subject to the Boost | 
|---|
|  | 38 | Software License, Version 1.0. (See accompanying file | 
|---|
|  | 39 | <code class="filename">LICENSE_1_0.txt</code> 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> | 
|---|
|  | 40 | </div></div> | 
|---|
|  | 41 | </div></div> | 
|---|
|  | 42 | <div class="toc"> | 
|---|
|  | 43 | <p><b>Table of Contents</b></p> | 
|---|
|  | 44 | <dl> | 
|---|
|  | 45 | <dt><span class="section"><a href="lambda.html#introduction">In a nutshell</a></span></dt> | 
|---|
|  | 46 | <dt><span class="section"><a href="lambda/getting_started.html">Getting Started</a></span></dt> | 
|---|
|  | 47 | <dd><dl> | 
|---|
|  | 48 | <dt><span class="section"><a href="lambda/getting_started.html#id1242965">Installing the library</a></span></dt> | 
|---|
|  | 49 | <dt><span class="section"><a href="lambda/getting_started.html#id1243250">Conventions used in this document</a></span></dt> | 
|---|
|  | 50 | </dl></dd> | 
|---|
|  | 51 | <dt><span class="section"><a href="lambda/s03.html">Introduction</a></span></dt> | 
|---|
|  | 52 | <dd><dl> | 
|---|
|  | 53 | <dt><span class="section"><a href="lambda/s03.html#id1243287">Motivation</a></span></dt> | 
|---|
|  | 54 | <dt><span class="section"><a href="lambda/s03.html#id1243548">Introduction to lambda expressions</a></span></dt> | 
|---|
|  | 55 | </dl></dd> | 
|---|
|  | 56 | <dt><span class="section"><a href="lambda/using_library.html">Using the library</a></span></dt> | 
|---|
|  | 57 | <dd><dl> | 
|---|
|  | 58 | <dt><span class="section"><a href="lambda/using_library.html#lambda.introductory_examples">Introductory Examples</a></span></dt> | 
|---|
|  | 59 | <dt><span class="section"><a href="lambda/using_library.html#lambda.parameter_and_return_types">Parameter and return types of lambda functors</a></span></dt> | 
|---|
|  | 60 | <dt><span class="section"><a href="lambda/using_library.html#lambda.actual_arguments_to_lambda_functors">About actual arguments to lambda functors</a></span></dt> | 
|---|
|  | 61 | <dt><span class="section"><a href="lambda/using_library.html#lambda.storing_bound_arguments">Storing bound arguments in lambda functions</a></span></dt> | 
|---|
|  | 62 | </dl></dd> | 
|---|
|  | 63 | <dt><span class="section"><a href="lambda/le_in_details.html">Lambda expressions in details</a></span></dt> | 
|---|
|  | 64 | <dd><dl> | 
|---|
|  | 65 | <dt><span class="section"><a href="lambda/le_in_details.html#lambda.placeholders">Placeholders</a></span></dt> | 
|---|
|  | 66 | <dt><span class="section"><a href="lambda/le_in_details.html#lambda.operator_expressions">Operator expressions</a></span></dt> | 
|---|
|  | 67 | <dt><span class="section"><a href="lambda/le_in_details.html#lambda.bind_expressions">Bind expressions</a></span></dt> | 
|---|
|  | 68 | <dt><span class="section"><a href="lambda/le_in_details.html#lambda.overriding_deduced_return_type">Overriding the deduced return type</a></span></dt> | 
|---|
|  | 69 | <dt><span class="section"><a href="lambda/le_in_details.html#lambda.delaying_constants_and_variables">Delaying constants and variables</a></span></dt> | 
|---|
|  | 70 | <dt><span class="section"><a href="lambda/le_in_details.html#lambda.lambda_expressions_for_control_structures">Lambda expressions for control structures</a></span></dt> | 
|---|
|  | 71 | <dt><span class="section"><a href="lambda/le_in_details.html#lambda.exceptions">Exceptions</a></span></dt> | 
|---|
|  | 72 | <dt><span class="section"><a href="lambda/le_in_details.html#lambda.construction_and_destruction">Construction and destruction</a></span></dt> | 
|---|
|  | 73 | <dt><span class="section"><a href="lambda/le_in_details.html#id1247290">Special lambda expressions</a></span></dt> | 
|---|
|  | 74 | <dt><span class="section"><a href="lambda/le_in_details.html#id1247769">Casts, sizeof and typeid</a></span></dt> | 
|---|
|  | 75 | <dt><span class="section"><a href="lambda/le_in_details.html#lambda.nested_stl_algorithms">Nesting STL algorithm invocations</a></span></dt> | 
|---|
|  | 76 | </dl></dd> | 
|---|
|  | 77 | <dt><span class="section"><a href="lambda/extending.html">Extending return type deduction system</a></span></dt> | 
|---|
|  | 78 | <dt><span class="section"><a href="lambda/s07.html">Practical considerations</a></span></dt> | 
|---|
|  | 79 | <dd><dl> | 
|---|
|  | 80 | <dt><span class="section"><a href="lambda/s07.html#id1248985">Performance</a></span></dt> | 
|---|
|  | 81 | <dt><span class="section"><a href="lambda/s07.html#id1249366">About compiling</a></span></dt> | 
|---|
|  | 82 | <dt><span class="section"><a href="lambda/s07.html#id1249416">Portability</a></span></dt> | 
|---|
|  | 83 | </dl></dd> | 
|---|
|  | 84 | <dt><span class="section"><a href="lambda/s08.html">Relation to other Boost libraries</a></span></dt> | 
|---|
|  | 85 | <dd><dl> | 
|---|
|  | 86 | <dt><span class="section"><a href="lambda/s08.html#id1249739">Boost Function</a></span></dt> | 
|---|
|  | 87 | <dt><span class="section"><a href="lambda/s08.html#id1249832">Boost Bind</a></span></dt> | 
|---|
|  | 88 | </dl></dd> | 
|---|
|  | 89 | <dt><span class="section"><a href="lambda/s09.html">Contributors</a></span></dt> | 
|---|
|  | 90 | <dt><span class="appendix"><a href="apa.html">A. Rationale for some of the design decisions</a></span></dt> | 
|---|
|  | 91 | <dd><dl><dt><span class="section"><a href="apa.html#lambda.why_weak_arity"> | 
|---|
|  | 92 | Lambda functor arity | 
|---|
|  | 93 | </a></span></dt></dl></dd> | 
|---|
|  | 94 | <dt><span class="bibliography"><a href="lambda.html#id1250088">Bibliography</a></span></dt> | 
|---|
|  | 95 | </dl> | 
|---|
|  | 96 | </div> | 
|---|
|  | 97 | <div class="section" lang="en"> | 
|---|
|  | 98 | <div class="titlepage"><div><div><h2 class="title" style="clear: both"> | 
|---|
|  | 99 | <a name="introduction"></a>In a nutshell</h2></div></div></div> | 
|---|
|  | 100 | <p> | 
|---|
|  | 101 |  | 
|---|
|  | 102 | The Boost Lambda Library (BLL in the sequel) is a C++ template | 
|---|
|  | 103 | library, which implements form of <span class="emphasis"><em>lambda abstractions</em></span> for C++. | 
|---|
|  | 104 | The term originates from functional programming and lambda calculus, where a lambda abstraction defines an unnamed function. | 
|---|
|  | 105 | The primary motivation for the BLL is to provide flexible and | 
|---|
|  | 106 | convenient means to define unnamed function objects for STL algorithms. | 
|---|
|  | 107 | In explaining what the library is about, a line of code says more than a thousand words; the | 
|---|
|  | 108 | following line outputs the elements of some STL container | 
|---|
|  | 109 | <code class="literal">a</code> separated by spaces: | 
|---|
|  | 110 |  | 
|---|
|  | 111 | </p> | 
|---|
|  | 112 | <pre class="programlisting">for_each(a.begin(), a.end(), std::cout << _1 << ' ');</pre> | 
|---|
|  | 113 | <p> | 
|---|
|  | 114 |  | 
|---|
|  | 115 | The expression <code class="literal">std::cout << _1 << ' '</code> defines a unary function object. | 
|---|
|  | 116 | The variable <code class="literal">_1</code> is the parameter of this function, a <span class="emphasis"><em>placeholder</em></span> for the actual argument. | 
|---|
|  | 117 | Within each iteration of <code class="literal">for_each</code>, the function is | 
|---|
|  | 118 | called with an element of <code class="literal">a</code> as the actual argument. | 
|---|
|  | 119 | This actual argument is substituted for the placeholder, and the “<span class="quote">body</span>” of the function is evaluated. | 
|---|
|  | 120 | </p> | 
|---|
|  | 121 | <p>The essence of BLL is letting you define small unnamed function objects, such as the one above, directly on the call site of an STL algorithm. | 
|---|
|  | 122 | </p> | 
|---|
|  | 123 | </div> | 
|---|
|  | 124 | <div class="bibliography"> | 
|---|
|  | 125 | <div class="titlepage"><div><div><h2 class="title"> | 
|---|
|  | 126 | <a name="id1250088"></a>Bibliography</h2></div></div></div> | 
|---|
|  | 127 | <div class="biblioentry"> | 
|---|
|  | 128 | <a name="cit:stepanov:94"></a><p>[<span class="abbrev">STL94</span>] <span class="authorgroup"><span class="firstname">A. A.</span> <span class="surname">Stepanov</span> and <span class="firstname">M.</span> <span class="surname">Lee</span>. </span><span class="title"><i>The Standard Template Library</i>. </span><span class="orgname">Hewlett-Packard Laboratories. </span><span class="pubdate">1994. </span><span class="bibliomisc"> | 
|---|
|  | 129 | <a href="http://www.hpl.hp.com/techreports" target="_top">www.hpl.hp.com/techreports</a> | 
|---|
|  | 130 | . </span></p> | 
|---|
|  | 131 | </div> | 
|---|
|  | 132 | <div class="biblioentry"> | 
|---|
|  | 133 | <a name="cit:sgi:02"></a><p>[<span class="abbrev">SGI02</span>] <span class="title"><i>The SGI Standard Template Library</i>. </span><span class="pubdate">2002. </span><span class="bibliomisc"><a href="http://www.sgi.com/tech/stl/" target="_top">www.sgi.com/tech/stl/</a>. </span></p> | 
|---|
|  | 134 | </div> | 
|---|
|  | 135 | <div class="biblioentry"> | 
|---|
|  | 136 | <a name="cit:c++:98"></a><p>[<span class="abbrev">C++98</span>] <span class="title"><i>International Standard, Programming Languages – C++</i>. </span><span class="subtitle">ISO/IEC:14882. </span><span class="pubdate">1998. </span></p> | 
|---|
|  | 137 | </div> | 
|---|
|  | 138 | <div class="biblioentry"> | 
|---|
|  | 139 | <a name="cit:jarvi:99"></a><p>[<span class="abbrev">Jär99</span>] <span class="articleinfo"> | 
|---|
|  | 140 | <span class="author"><span class="firstname">Jaakko</span> <span class="surname">Järvi</span>. </span> | 
|---|
|  | 141 | <span class="title"><i>C++ Function Object Binders Made Easy</i>. </span> | 
|---|
|  | 142 | . </span><span class="title"><i>Lecture Notes in Computer Science</i>. </span><span class="volumenum">1977. </span><span class="publishername">Springer. </span><span class="pubdate">2000. </span></p> | 
|---|
|  | 143 | </div> | 
|---|
|  | 144 | <div class="biblioentry"> | 
|---|
|  | 145 | <a name="cit:jarvi:00"></a><p>[<span class="abbrev">Jär00</span>] <span class="author"><span class="firstname">Jaakko</span> <span class="surname">Järvi</span>. </span><span class="author"><span class="firstname">Gary</span> <span class="surname">Powell</span>. </span><span class="title"><i>The Lambda Library : Lambda Abstraction in C++</i>. </span><span class="orgname">Turku Centre for Computer Science. </span><span class="bibliomisc">Technical Report . </span><span class="issuenum">378. </span><span class="pubdate">2000. </span><span class="bibliomisc"><a href="http://www.tucs.fi/Publications/techreports/TR378.php" target="_top">www.tucs.fi/publications</a>. </span></p> | 
|---|
|  | 146 | </div> | 
|---|
|  | 147 | <div class="biblioentry"> | 
|---|
|  | 148 | <a name="cit:jarvi:01"></a><p>[<span class="abbrev">Jär01</span>] <span class="author"><span class="firstname">Jaakko</span> <span class="surname">Järvi</span>. </span><span class="author"><span class="firstname">Gary</span> <span class="surname">Powell</span>. </span><span class="title"><i>The Lambda Library : Lambda Abstraction in C++</i>. </span><span class="confgroup"><span class="conftitle">Second  Workshop on C++ Template Programming. </span><span class="address">Tampa Bay, OOPSLA'01. </span>. </span><span class="pubdate">2001. </span><span class="bibliomisc"><a href="http://www.oonumerics.org/tmpw01/" target="_top">www.oonumerics.org/tmpw01/</a>. </span></p> | 
|---|
|  | 149 | </div> | 
|---|
|  | 150 | <div class="biblioentry"> | 
|---|
|  | 151 | <a name="cit:jarvi:03"></a><p>[<span class="abbrev">Jär03</span>] <span class="articleinfo"> | 
|---|
|  | 152 |  | 
|---|
|  | 153 | <span class="author"><span class="firstname">Jaakko</span> <span class="surname">Järvi</span>. </span> | 
|---|
|  | 154 |  | 
|---|
|  | 155 | <span class="author"><span class="firstname">Gary</span> <span class="surname">Powell</span>. </span> | 
|---|
|  | 156 |  | 
|---|
|  | 157 | <span class="author"><span class="firstname">Andrew</span> <span class="surname">Lumsdaine</span>. </span> | 
|---|
|  | 158 | <span class="title"><i>The Lambda Library : unnamed functions in C++</i>. </span> | 
|---|
|  | 159 |  | 
|---|
|  | 160 | . </span><span class="title"><i>Software - Practice and Expreience</i>. </span><span class="volumenum">33:259-291. </span><span class="pubdate">2003. </span></p> | 
|---|
|  | 161 | </div> | 
|---|
|  | 162 | <div class="biblioentry"> | 
|---|
|  | 163 | <a name="cit:boost::tuple"></a><p>[<span class="abbrev">tuple</span>] <span class="title"><i>The Boost Tuple Library</i>. </span><span class="bibliomisc"><a href="http://www.boost.org/libs/tuple/doc/tuple_users_guide.html" target="_top">www.boost.org/libs/tuple/doc/tuple_users_guide.html</a> | 
|---|
|  | 164 | . </span><span class="pubdate">2002. </span></p> | 
|---|
|  | 165 | </div> | 
|---|
|  | 166 | <div class="biblioentry"> | 
|---|
|  | 167 | <a name="cit:boost::type_traits"></a><p>[<span class="abbrev">type_traits</span>] <span class="title"><i>The Boost type_traits</i>. </span><span class="bibliomisc"><a href="http://www.boost.org/libs/type_traits/index.htm" target="_top">www.boost.org/libs/type_traits/</a> | 
|---|
|  | 168 | . </span><span class="pubdate">2002. </span></p> | 
|---|
|  | 169 | </div> | 
|---|
|  | 170 | <div class="biblioentry"> | 
|---|
|  | 171 | <a name="cit:boost::ref"></a><p>[<span class="abbrev">ref</span>] <span class="title"><i>Boost ref</i>. </span><span class="bibliomisc"><a href="http://www.boost.org/libs/bind/ref.html" target="_top">www.boost.org/libs/bind/ref.html</a> | 
|---|
|  | 172 | . </span><span class="pubdate">2002. </span></p> | 
|---|
|  | 173 | </div> | 
|---|
|  | 174 | <div class="biblioentry"> | 
|---|
|  | 175 | <a name="cit:boost::bind"></a><p>[<span class="abbrev">bind</span>] <span class="title"><i>Boost Bind Library</i>. </span><span class="bibliomisc"><a href="http://www.boost.org/libs/bind/bind.html" target="_top">www.boost.org/libs/bind/bind.html</a> | 
|---|
|  | 176 | . </span><span class="pubdate">2002. </span></p> | 
|---|
|  | 177 | </div> | 
|---|
|  | 178 | <div class="biblioentry"> | 
|---|
|  | 179 | <a name="cit:boost::function"></a><p>[<span class="abbrev">function</span>] <span class="title"><i>Boost Function Library</i>. </span><span class="bibliomisc"><a href="http://www.boost.org/libs/function/" target="_top">www.boost.org/libs/function/</a> | 
|---|
|  | 180 | . </span><span class="pubdate">2002. </span></p> | 
|---|
|  | 181 | </div> | 
|---|
|  | 182 | <div class="biblioentry"> | 
|---|
|  | 183 | <a name="cit:fc++"></a><p>[<span class="abbrev">fc++</span>] <span class="title"><i>The FC++ library: Functional Programming in C++</i>. </span><span class="author"><span class="firstname">Yannis</span> <span class="surname">Smaragdakis</span>. </span><span class="author"><span class="firstname">Brian</span> <span class="surname">McNamara</span>. </span><span class="bibliomisc"><a href="http://www.cc.gatech.edu/~yannis/fc++/" target="_top">www.cc.gatech.edu/~yannis/fc++/</a> | 
|---|
|  | 184 | . </span><span class="pubdate">2002. </span></p> | 
|---|
|  | 185 | </div> | 
|---|
|  | 186 | </div> | 
|---|
|  | 187 | </div> | 
|---|
|  | 188 | <table width="100%"><tr> | 
|---|
|  | 189 | <td align="left"><small><p>Last revised: November 29, 2006 at 19:28:48 GMT</p></small></td> | 
|---|
|  | 190 | <td align="right"><small></small></td> | 
|---|
|  | 191 | </tr></table> | 
|---|
|  | 192 | <hr> | 
|---|
|  | 193 | <div class="spirit-nav"> | 
|---|
|  | 194 | <a accesskey="p" href="hash/acknowledgements.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="libraries.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="lambda/getting_started.html"><img src="images/next.png" alt="Next"></a> | 
|---|
|  | 195 | </div> | 
|---|
|  | 196 | </body> | 
|---|
|  | 197 | </html> | 
|---|