mirror of
https://github.com/boostorg/lambda.git
synced 2026-01-21 04:52:25 +00:00
Compare commits
3 Commits
svn-tags/m
...
boost-1.31
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccd0d77c1c | ||
|
|
ee5a93d90f | ||
|
|
9df574d2ad |
@@ -5,7 +5,7 @@
|
||||
The Boost Lambda Library"><link rel="up" href="index.html" title="
|
||||
C++ BOOST
|
||||
|
||||
The Boost Lambda Library"><link rel="previous" href="ar01s09.html" title="9. Contributors"><link rel="next" href="bi01.html" title="Bibliography"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">A. Rationale for some of the design decisions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s09.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="bi01.html">Next</a></td></tr></table><hr></div><div class="appendix"><h2 class="title" style="clear: both"><a name="id2808845"></a>A. Rationale for some of the design decisions</h2><div class="section"><div class="titlepage"><div><h3 class="title"><a name="sect:why_weak_arity"></a>1.
|
||||
The Boost Lambda Library"><link rel="previous" href="ar01s09.html" title="9. Contributors"><link rel="next" href="bi01.html" title="Bibliography"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">A. Rationale for some of the design decisions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s09.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="bi01.html">Next</a></td></tr></table><hr></div><div class="appendix"><h2 class="title" style="clear: both"><a name="id2828267"></a>A. Rationale for some of the design decisions</h2><div class="section"><div class="titlepage"><div><h3 class="title"><a name="sect:why_weak_arity"></a>1.
|
||||
Lambda functor arity
|
||||
</h3></div></div><p>
|
||||
The highest placeholder index in a lambda expression determines the arity of the resulting function object.
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
The Boost Lambda Library"><link rel="previous" href="index.html" title="
|
||||
C++ BOOST
|
||||
|
||||
The Boost Lambda Library"><link rel="next" href="ar01s03.html" title="3. Introduction"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2. Getting Started</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="index.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s03.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="sect:getting_started"></a>2. Getting Started</h2></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2790118"></a>2.1. Installing the library</h3></div></div><p>
|
||||
The Boost Lambda Library"><link rel="next" href="ar01s03.html" title="3. Introduction"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2. Getting Started</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="index.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s03.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="sect:getting_started"></a>2. Getting Started</h2></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2761975"></a>2.1. Installing the library</h3></div></div><p>
|
||||
The library consists of include files only, hence there is no
|
||||
installation procedure. The <tt>boost</tt> include directory
|
||||
must be on the include path.
|
||||
@@ -44,7 +44,7 @@ Cast expressions
|
||||
<span class="emphasis"><i>Tuple</i></span> [<a href="bi01.html#cit:boost::tuple" title="[tuple]">tuple</a>] and the <span class="emphasis"><i>type_traits</i></span> [<a href="bi01.html#cit:boost::type_traits" title="[type_traits]">type_traits</a>] libraries, and on the <tt>boost/ref.hpp</tt> header.
|
||||
</p><p>
|
||||
All definitions are placed in the namespace <tt>boost::lambda</tt> and its subnamespaces.
|
||||
</p></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2741945"></a>2.2. Conventions used in this document</h3></div></div><p>In most code examples, we omit the namespace prefixes for names in the <tt>std</tt> and <tt>boost::lambda</tt> namespaces.
|
||||
</p></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2762422"></a>2.2. Conventions used in this document</h3></div></div><p>In most code examples, we omit the namespace prefixes for names in the <tt>std</tt> and <tt>boost::lambda</tt> namespaces.
|
||||
Implicit using declarations
|
||||
<pre class="programlisting">
|
||||
using namespace std;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
The Boost Lambda Library"><link rel="up" href="index.html" title="
|
||||
C++ BOOST
|
||||
|
||||
The Boost Lambda Library"><link rel="previous" href="ar01s02.html" title="2. Getting Started"><link rel="next" href="ar01s04.html" title="4. Using the library"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3. Introduction</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s02.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s04.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2741991"></a>3. Introduction</h2></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2741999"></a>3.1. Motivation</h3></div></div><p>The Standard Template Library (STL)
|
||||
[<a href="bi01.html#cit:stepanov:94" title="[STL94]">STL94</a>], now part of the C++ Standard Library [<a href="bi01.html#cit:c++:98" title="[C++98]">C++98</a>], is a generic container and algorithm library.
|
||||
The Boost Lambda Library"><link rel="previous" href="ar01s02.html" title="2. Getting Started"><link rel="next" href="ar01s04.html" title="4. Using the library"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3. Introduction</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s02.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s04.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2762461"></a>3. Introduction</h2></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2762467"></a>3.1. Motivation</h3></div></div><p>The Standard Template Library (STL)
|
||||
[<a href="bi01.html#cit:stepanov:94" title="[STL94]">STL94</a>], now part of the C++ Standard Library [<a href="bi01.html#cit:c%2B%2B:98" title="[C++98]">C++98</a>], is a generic container and algorithm library.
|
||||
Typically STL algorithms operate on container elements via <span class="emphasis"><i>function objects</i></span>. These function objects are passed as arguments to the algorithms.
|
||||
</p><p>
|
||||
Any C++ construct that can be called with the function call syntax
|
||||
@@ -105,7 +105,7 @@ as function composition is supported implicitly.
|
||||
|
||||
</p></li></ul></div>
|
||||
|
||||
</p></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2742792"></a>3.2. Introduction to lambda expressions</h3></div></div><p>
|
||||
</p></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2762797"></a>3.2. Introduction to lambda expressions</h3></div></div><p>
|
||||
Lambda expression are common in functional programming languages.
|
||||
Their syntax varies between languages (and between different forms of lambda calculus), but the basic form of a lambda expressions is:
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ There are quite a lot of exceptions and special cases, but discussion of them is
|
||||
list<int> v(10);
|
||||
for_each(v.begin(), v.end(), _1 = 1);</pre>
|
||||
|
||||
The expression <tt>_1 = 1</tt> creates a lambda functor which assigns the value <tt>1</tt> to every element in <tt>v</tt>.<sup>[<a name="id2739596" href="#ftn.id2739596">1</a>]</sup>
|
||||
The expression <tt>_1 = 1</tt> creates a lambda functor which assigns the value <tt>1</tt> to every element in <tt>v</tt>.<sup>[<a name="id2758769" href="#ftn.id2758769">1</a>]</sup>
|
||||
</p><p>
|
||||
Next, we create a container of pointers and make them point to the elements in the first container <tt>v</tt>:
|
||||
|
||||
@@ -205,7 +205,7 @@ This is to prevent pointer arithmetic making non-const arrays const.
|
||||
</p></li></ul></div>
|
||||
|
||||
</p></li></ul></div>
|
||||
</p></div><div class="footnotes"><br><hr width="100" align="left"><div class="footnote"><p><sup>[<a name="ftn.id2739596" href="#id2739596">1</a>] </sup>
|
||||
</p></div><div class="footnotes"><br><hr width="100" align="left"><div class="footnote"><p><sup>[<a name="ftn.id2758769" href="#id2758769">1</a>] </sup>
|
||||
Strictly taken, the C++ standard defines <tt>for_each</tt> as a <span class="emphasis"><i>non-modifying sequence operation</i></span>, and the function object passed to <tt>for_each</tt> should not modify its argument.
|
||||
The requirements for the arguments of <tt>for_each</tt> are unnecessary strict, since as long as the iterators are <span class="emphasis"><i>mutable</i></span>, <tt>for_each</tt> accepts a function object that can have side-effects on their argument.
|
||||
Nevertheless, it is straightforward to provide another function template with the functionality of<tt>std::for_each</tt> but more fine-grained requirements for its arguments.
|
||||
|
||||
@@ -77,7 +77,7 @@ For example, the following is a valid lambda expression:
|
||||
<pre class="programlisting">cout << _1, _2[_3] = _1 && false</pre>
|
||||
</p><p>
|
||||
However, there are some restrictions that originate from the C++ operator overloading rules, and some special cases.
|
||||
</p><div class="section"><div class="titlepage"><div><h4 class="title"><a name="id2740648"></a>5.2.1. Operators that cannot be overloaded</h4></div></div><p>
|
||||
</p><div class="section"><div class="titlepage"><div><h4 class="title"><a name="id2759856"></a>5.2.1. Operators that cannot be overloaded</h4></div></div><p>
|
||||
Some operators cannot be overloaded at all (<tt>::</tt>, <tt>.</tt>, <tt>.*</tt>).
|
||||
For some operators, the requirements on return types prevent them to be overloaded to create lambda functors.
|
||||
These operators are <tt>->.</tt>, <tt>-></tt>, <tt>new</tt>, <tt>new[]</tt>, <tt>delete</tt>, <tt>delete[]</tt> and <tt>?:</tt> (the conditional operator).
|
||||
@@ -105,7 +105,7 @@ bool flag = true; int i = 0;
|
||||
(_1 || ++_2)(flag, i);
|
||||
</pre>
|
||||
</p></div><div class="section"><div class="titlepage"><div><h4 class="title"><a name="sect:comma_operator"></a>5.2.4. Comma operator</h4></div></div><p>
|
||||
Comma operator is the ‘statement separator’ in lambda expressions.
|
||||
Comma operator is the “statement separator” in lambda expressions.
|
||||
Since comma is also the separator between arguments in a function call, extra parenthesis are sometimes needed:
|
||||
|
||||
<pre class="programlisting">
|
||||
@@ -308,32 +308,12 @@ operator defined, can be used as target functions.
|
||||
|
||||
In general, BLL cannot deduce the return type of an arbitrary function object.
|
||||
|
||||
However, there are two methods for giving BLL this capability for a certain
|
||||
However, there is a method for giving BLL this capability for a certain
|
||||
function object class.
|
||||
|
||||
</p><div class="simplesect"><div class="titlepage"><div><h5 class="title"><a name="id2803250"></a>The result_type typedef</h5></div></div><p>
|
||||
|
||||
The BLL supports the standard library convention of declaring the return type
|
||||
of a function object with a member typedef named <tt>result_type</tt> in the
|
||||
function object class.
|
||||
|
||||
Here is a simple example:
|
||||
<pre class="programlisting">
|
||||
struct A {
|
||||
typedef B result_type;
|
||||
B operator()(X, Y, Z);
|
||||
};
|
||||
</pre>
|
||||
|
||||
If a function object does not define a <tt>result_type</tt> typedef,
|
||||
the method described below (<tt>sig</tt> template)
|
||||
is attempted to resolve the return type of the
|
||||
function object. If a function object defines both <tt>result_type</tt>
|
||||
and <tt>sig</tt>, <tt>result_type</tt> takes precedence.
|
||||
|
||||
</p></div><div class="simplesect"><div class="titlepage"><div><h5 class="title"><a name="id2803321"></a>The sig template</h5></div></div><p>
|
||||
Another mechanism that make BLL aware of the return type(s) of a function object is defining
|
||||
member template struct
|
||||
</p><div class="simplesect"><div class="titlepage"><div><h5 class="title"><a name="id2822731"></a>The sig template</h5></div></div><p>
|
||||
To make BLL aware of the return type(s) of a function object one needs to
|
||||
provide a member template struct
|
||||
<tt>sig<Args></tt> with a typedef
|
||||
<tt>type</tt> that specifies the return type.
|
||||
|
||||
@@ -352,7 +332,9 @@ is the function
|
||||
object type itself, and the remaining elements are the types of
|
||||
the arguments, with which the function object is being called.
|
||||
|
||||
This may seem overly complex compared to defining the <tt>result_type</tt> typedef.
|
||||
This may seem overly complex compared to the Standard Library
|
||||
convention for defining the return type of a function
|
||||
object with the <tt>return_type</tt> typedef.
|
||||
Howver, there are two significant restrictions with using just a simple
|
||||
typedef to express the return type:
|
||||
<div class="orderedlist"><ol type="1"><li><p>
|
||||
@@ -413,8 +395,26 @@ Tuple [<a href="bi01.html#cit:boost::type_traits" title="[type_traits]">type_tra
|
||||
for tools that can aid in these tasks.
|
||||
The <tt>sig</tt> templates are a refined version of a similar
|
||||
mechanism first introduced in the FC++ library
|
||||
[<a href="bi01.html#cit:fc++" title="[fc++]">fc++</a>].
|
||||
</p></div></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="sect:overriding_deduced_return_type"></a>5.4. Overriding the deduced return type</h3></div></div><p>
|
||||
[<a href="bi01.html#cit:fc%2B%2B" title="[fc++]">fc++</a>].
|
||||
</p></div><p>
|
||||
Earlier versions of the library supported the Standard Library convention
|
||||
as the default, and required special actions to make the library recognize
|
||||
the <tt>sig</tt> template.
|
||||
Now the BLL has that reversed.
|
||||
|
||||
If one needs to use a functor that adheres to the Standard Library
|
||||
convention in a bind expression, we provide the <tt>std_functor</tt>
|
||||
wrapper, that gives the function object a <tt>sig</tt>
|
||||
template based on the <tt>result_type</tt> typedef.
|
||||
For example:
|
||||
|
||||
<pre class="programlisting">
|
||||
int i = 1;
|
||||
bind(plus<int>(), _1, 1)(i); // error, no sig template
|
||||
bind(std_functor(plus<int>()), _1, 1)(i); // ok
|
||||
</pre>
|
||||
|
||||
</p></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="sect:overriding_deduced_return_type"></a>5.4. Overriding the deduced return type</h3></div></div><p>
|
||||
The return type deduction system may not be able to deduce the return types of some user defined operators or bind expressions with class objects.
|
||||
|
||||
A special lambda expression type is provided for stating the return type explicitly and overriding the deduction system.
|
||||
@@ -533,7 +533,7 @@ By using <tt>var</tt> to make <tt>index</tt> a lambda expression, we get the des
|
||||
In sum, <tt>var(x)</tt> creates a nullary lambda functor,
|
||||
which stores a reference to the variable <tt>x</tt>.
|
||||
When the lambda functor is invoked, a reference to <tt>x</tt> is returned.
|
||||
</p><div class="simplesect"><div class="titlepage"><div><h4 class="title"><a name="id2804115"></a>Naming delayed constants and variables</h4></div></div><p>
|
||||
</p><div class="simplesect"><div class="titlepage"><div><h4 class="title"><a name="id2823567"></a>Naming delayed constants and variables</h4></div></div><p>
|
||||
It is possible to predefine and name a delayed variable or constant outside a lambda expression.
|
||||
The templates <tt>var_type</tt>, <tt>constant_type</tt>
|
||||
and <tt>constant_ref_type</tt> serve for this purpose.
|
||||
@@ -562,7 +562,7 @@ Here is an example of naming a delayed constant:
|
||||
constant_type<char>::type space(constant(' '));
|
||||
for_each(a.begin(),a.end(), cout << space << _1);
|
||||
</pre>
|
||||
</p></div><div class="simplesect"><div class="titlepage"><div><h4 class="title"><a name="id2804238"></a>About assignment and subscript operators</h4></div></div><p>
|
||||
</p></div><div class="simplesect"><div class="titlepage"><div><h4 class="title"><a name="id2823690"></a>About assignment and subscript operators</h4></div></div><p>
|
||||
As described in <a href="ar01s05.html#sect:assignment_and_subscript" title="5.2.2. Assignment and subscript operators">Section 5.2.2</a>, assignment and subscripting operators are always defined as member functions.
|
||||
This means, that for expressions of the form
|
||||
<tt>x = y</tt> or <tt>x[y]</tt> to be interpreted as lambda expressions, the left-hand operand <tt>x</tt> must be a lambda expression.
|
||||
@@ -850,7 +850,7 @@ objects related to creating and destroying objects,
|
||||
showing the expression to create and call the function object,
|
||||
and the effect of evaluating that expression.
|
||||
|
||||
</p><div class="table"><p><a name="table:constructor_destructor_fos"></a><b>Table 1. Construction and destruction related function objects.</b></p><table summary="Construction and destruction related function objects." border="1"><colgroup><col><col></colgroup><thead><tr><th>Function object call</th><th>Wrapped expression</th></tr></thead><tbody><tr><td><tt>constructor<T>()(<i><tt>arg_list</tt></i>)</tt></td><td>T(<i><tt>arg_list</tt></i>)</td></tr><tr><td><tt>destructor()(a)</tt></td><td><tt>a.~A()</tt>, where <tt>a</tt> is of type <tt>A</tt></td></tr><tr><td><tt>destructor()(pa)</tt></td><td><tt>pa->~A()</tt>, where <tt>pa</tt> is of type <tt>A*</tt></td></tr><tr><td><tt>new_ptr<T>()(<i><tt>arg_list</tt></i>)</tt></td><td><tt>new T(<i><tt>arg_list</tt></i>)</tt></td></tr><tr><td><tt>new_array<T>()(sz)</tt></td><td><tt>new T[sz]</tt></td></tr><tr><td><tt>delete_ptr()(p)</tt></td><td><tt>delete p</tt></td></tr><tr><td><tt>delete_array()(p)</tt></td><td><tt>delete p[]</tt></td></tr></tbody></table></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2805507"></a>5.9. Special lambda expressions</h3></div></div><div class="section"><div class="titlepage"><div><h4 class="title"><a name="id2805514"></a>5.9.1. Preventing argument substitution</h4></div></div><p>
|
||||
</p><div class="table"><p><a name="table:constructor_destructor_fos"></a><b>Table 1. Construction and destruction related function objects.</b></p><table summary="Construction and destruction related function objects." border="1"><colgroup><col><col></colgroup><thead><tr><th>Function object call</th><th>Wrapped expression</th></tr></thead><tbody><tr><td><tt>constructor<T>()(<i><tt>arg_list</tt></i>)</tt></td><td>T(<i><tt>arg_list</tt></i>)</td></tr><tr><td><tt>destructor()(a)</tt></td><td><tt>a.~A()</tt>, where <tt>a</tt> is of type <tt>A</tt></td></tr><tr><td><tt>destructor()(pa)</tt></td><td><tt>pa.->A()</tt>, where <tt>pa</tt> is of type <tt>A*</tt></td></tr><tr><td><tt>new_ptr<T>()(<i><tt>arg_list</tt></i>)</tt></td><td><tt>new T(<i><tt>arg_list</tt></i>)</tt></td></tr><tr><td><tt>new_array<T>()(sz)</tt></td><td><tt>new T[sz]</tt></td></tr><tr><td><tt>delete_ptr()(p)</tt></td><td><tt>delete p</tt></td></tr><tr><td><tt>delete_array()(p)</tt></td><td><tt>delete p[]</tt></td></tr></tbody></table></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2824949"></a>5.9. Special lambda expressions</h3></div></div><div class="section"><div class="titlepage"><div><h4 class="title"><a name="id2824956"></a>5.9.1. Preventing argument substitution</h4></div></div><p>
|
||||
When a lambda functor is called, the default behavior is to substitute
|
||||
the actual arguments for the placeholders within all subexpressions.
|
||||
|
||||
@@ -976,7 +976,7 @@ int nested(const F& f) {
|
||||
}
|
||||
</pre>
|
||||
|
||||
</p></div><div class="section"><div class="titlepage"><div><h5 class="title"><a name="id2805774"></a>5.9.1.2. Protect</h5></div></div><p>
|
||||
</p></div><div class="section"><div class="titlepage"><div><h5 class="title"><a name="id2825213"></a>5.9.1.2. Protect</h5></div></div><p>
|
||||
The <tt>protect</tt> function is related to unlambda.
|
||||
|
||||
It is also used to prevent the argument substitution taking place,
|
||||
@@ -1081,7 +1081,7 @@ since calls to sub lambda functors are made inside the BLL,
|
||||
and are not affected by the non-const rvalue problem.
|
||||
</p></li></ol></div>
|
||||
|
||||
</p></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2806080"></a>5.10. Casts, sizeof and typeid</h3></div></div><div class="section"><div class="titlepage"><div><h4 class="title"><a name="sect:cast_expressions"></a>5.10.1.
|
||||
</p></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2825516"></a>5.10. Casts, sizeof and typeid</h3></div></div><div class="section"><div class="titlepage"><div><h4 class="title"><a name="sect:cast_expressions"></a>5.10.1.
|
||||
Cast expressions
|
||||
</h4></div></div><p>
|
||||
The BLL defines its counterparts for the four cast expressions
|
||||
@@ -1110,7 +1110,7 @@ int count = 0;
|
||||
for_each(a.begin(), a.end(),
|
||||
if_then(ll_dynamic_cast<derived*>(_1), ++var(count)));
|
||||
</pre>
|
||||
</p></div><div class="section"><div class="titlepage"><div><h4 class="title"><a name="id2806181"></a>5.10.2. Sizeof and typeid</h4></div></div><p>
|
||||
</p></div><div class="section"><div class="titlepage"><div><h4 class="title"><a name="id2825617"></a>5.10.2. Sizeof and typeid</h4></div></div><p>
|
||||
The BLL counterparts for these expressions are named
|
||||
<tt>ll_sizeof</tt> and <tt>ll_typeid</tt>.
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
The Boost Lambda Library"><link rel="up" href="index.html" title="
|
||||
C++ BOOST
|
||||
|
||||
The Boost Lambda Library"><link rel="previous" href="ar01s06.html" title="6. Extending return type deduction system"><link rel="next" href="ar01s08.html" title="8. Relation to other Boost libraries"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">7. Practical considerations</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s06.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s08.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2807588"></a>7. Practical considerations</h2></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2807595"></a>7.1. Performance</h3></div></div><p>In theory, all overhead of using STL algorithms and lambda functors
|
||||
The Boost Lambda Library"><link rel="previous" href="ar01s06.html" title="6. Extending return type deduction system"><link rel="next" href="ar01s08.html" title="8. Relation to other Boost libraries"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">7. Practical considerations</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s06.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s08.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2827018"></a>7. Practical considerations</h2></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2827024"></a>7.1. Performance</h3></div></div><p>In theory, all overhead of using STL algorithms and lambda functors
|
||||
compared to hand written loops can be optimized away, just as the overhead
|
||||
from standard STL function objects and binders can.
|
||||
|
||||
@@ -97,7 +97,7 @@ The running times are expressed in arbitrary units." border="1"><colgroup><col><
|
||||
</p><p>Some additional performance testing with an earlier version of the
|
||||
library is described
|
||||
[<a href="bi01.html#cit:jarvi:00" title="[Jär00]">Jär00</a>].
|
||||
</p></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2808087"></a>7.2. About compiling</h3></div></div><p>The BLL uses templates rather heavily, performing numerous recursive instantiations of the same templates.
|
||||
</p></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2827515"></a>7.2. About compiling</h3></div></div><p>The BLL uses templates rather heavily, performing numerous recursive instantiations of the same templates.
|
||||
This has (at least) three implications:
|
||||
<div class="itemizedlist"><ul type="disc"><li><p>
|
||||
While it is possible to write incredibly complex lambda expressions, it probably isn't a good idea.
|
||||
@@ -111,7 +111,7 @@ This can make the error messages very long and difficult to interpret, particula
|
||||
The C++ Standard suggests a template nesting level of 17 to help detect infinite recursion.
|
||||
Complex lambda templates can easily exceed this limit.
|
||||
Most compilers allow a greater number of nested templates, but commonly require the limit explicitly increased with a command line argument.
|
||||
</p></li></ul></div></p></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2808149"></a>7.3. Portability</h3></div></div><p>
|
||||
</p></li></ul></div></p></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2827576"></a>7.3. Portability</h3></div></div><p>
|
||||
The BLL works with the following compilers, that is, the compilers are capable of compiling the test cases that are included with the BLL:
|
||||
|
||||
<div class="itemizedlist"><ul type="disc"><li>GCC 3.0.4
|
||||
@@ -120,7 +120,7 @@ The BLL works with the following compilers, that is, the compilers are capable o
|
||||
)
|
||||
|
||||
</li></ul></div>
|
||||
</p><div class="section"><div class="titlepage"><div><h4 class="title"><a name="id2808188"></a>7.3.1. Test coverage</h4></div></div><p>The following list describes the test files included and the features that each file covers:
|
||||
</p><div class="section"><div class="titlepage"><div><h4 class="title"><a name="id2827614"></a>7.3.1. Test coverage</h4></div></div><p>The following list describes the test files included and the features that each file covers:
|
||||
|
||||
<div class="itemizedlist"><ul type="disc"><li><p>
|
||||
<tt>bind_tests_simple.cpp</tt> : Bind expressions of different arities and types of target functions: function pointers, function objects and member functions.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
The Boost Lambda Library"><link rel="up" href="index.html" title="
|
||||
C++ BOOST
|
||||
|
||||
The Boost Lambda Library"><link rel="previous" href="ar01s07.html" title="7. Practical considerations"><link rel="next" href="ar01s09.html" title="9. Contributors"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">8. Relation to other Boost libraries</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s07.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s09.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2808533"></a>8. Relation to other Boost libraries</h2></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2808540"></a>8.1. Boost Function</h3></div></div><p>Sometimes it is convenient to store lambda functors in variables.
|
||||
The Boost Lambda Library"><link rel="previous" href="ar01s07.html" title="7. Practical considerations"><link rel="next" href="ar01s09.html" title="9. Contributors"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">8. Relation to other Boost libraries</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s07.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s09.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2827958"></a>8. Relation to other Boost libraries</h2></div></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2827965"></a>8.1. Boost Function</h3></div></div><p>Sometimes it is convenient to store lambda functors in variables.
|
||||
However, the types of even the simplest lambda functors are long and unwieldy, and it is in general unfeasible to declare variables with lambda functor types.
|
||||
<span class="emphasis"><i>The Boost Function library</i></span> [<a href="bi01.html#cit:boost::function" title="[function]">function</a>] defines wrappers for arbitrary function objects, for example
|
||||
lambda functors; and these wrappers have types that are easy to type out.
|
||||
@@ -44,7 +44,7 @@ delete sum;
|
||||
counter(3); // error, *sum does not exist anymore
|
||||
</pre>
|
||||
|
||||
</p></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2808644"></a>8.2. Boost Bind</h3></div></div><p>
|
||||
</p></div><div class="section"><div class="titlepage"><div><h3 class="title"><a name="id2828068"></a>8.2. Boost Bind</h3></div></div><p>
|
||||
<span class="emphasis"><i>The Boost Bind</i></span> [<a href="bi01.html#cit:boost::bind" title="[bind]">bind</a>] library has partially overlapping functionality with the BLL.
|
||||
Basically, the Boost Bind library (BB in the sequel) implements the bind expression part of BLL.
|
||||
There are, however, some semantical differerences.
|
||||
@@ -63,7 +63,7 @@ a larger set of compilers.
|
||||
</p><p>
|
||||
The following two sections describe what are the semantic differences
|
||||
between the bind expressions in BB and BLL.
|
||||
</p><div class="section"><div class="titlepage"><div><h4 class="title"><a name="id2808709"></a>8.2.1. First argument of bind expression</h4></div></div>
|
||||
</p><div class="section"><div class="titlepage"><div><h4 class="title"><a name="id2828132"></a>8.2.1. First argument of bind expression</h4></div></div>
|
||||
|
||||
In BB the first argument of the bind expression, the target function,
|
||||
is treated differently from the other arguments,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
The Boost Lambda Library"><link rel="up" href="index.html" title="
|
||||
C++ BOOST
|
||||
|
||||
The Boost Lambda Library"><link rel="previous" href="ar01s08.html" title="8. Relation to other Boost libraries"><link rel="next" href="apa.html" title="A. Rationale for some of the design decisions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">9. Contributors</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s08.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="apa.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2808824"></a>9. Contributors</h2></div></div>
|
||||
The Boost Lambda Library"><link rel="previous" href="ar01s08.html" title="8. Relation to other Boost libraries"><link rel="next" href="apa.html" title="A. Rationale for some of the design decisions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">9. Contributors</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ar01s08.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="apa.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2828245"></a>9. Contributors</h2></div></div>
|
||||
|
||||
The main body of the library was written by Jaakko Järvi and Gary Powell.
|
||||
We've got outside help, suggestions and ideas from Jeremy Siek, Peter Higley, Peter Dimov, Valentin Bonnard, William Kempf.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
The Boost Lambda Library"><link rel="up" href="index.html" title="
|
||||
C++ BOOST
|
||||
|
||||
The Boost Lambda Library"><link rel="previous" href="apa.html" title="A. Rationale for some of the design decisions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Bibliography</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apa.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> </td></tr></table><hr></div><div id="id2808997" class="bibliography"><div class="titlepage"><div><h2 class="title"><a name="id2808997"></a>Bibliography</h2></div></div><div class="biblioentry"><a name="cit:stepanov:94"></a><p>[STL94] <span class="authorgroup">A. A. Stepanov and M. Lee. </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">
|
||||
The Boost Lambda Library"><link rel="previous" href="apa.html" title="A. Rationale for some of the design decisions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Bibliography</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apa.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> </td></tr></table><hr></div><div id="id2828417" class="bibliography"><div class="titlepage"><div><h2 class="title"><a name="id2828417"></a>Bibliography</h2></div></div><div class="biblioentry"><a name="cit:stepanov:94"></a><p>[STL94] <span class="authorgroup">A. A. Stepanov and M. Lee. </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">
|
||||
<a href="http://www.hpl.hp.com/techreports" target="_top">www.hpl.hp.com/techreports</a>
|
||||
. </span></p></div><div class="biblioentry"><a name="cit:sgi:02"></a><p>[SGI02] <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></div><div class="biblioentry"><a name="cit:c++:98"></a><p>[C++98] <span class="title"><I>International Standard, Programming Languages – C++</I>. </span><span class="subtitle">ISO/IEC:14882. </span><span class="pubdate">1998. </span></p></div><div class="biblioentry"><a name="cit:jarvi:99"></a><p>[Jär99] <span class="articleinfo">
|
||||
<span class="author">Jaakko Järvi. </span>
|
||||
@@ -24,5 +24,5 @@
|
||||
. </span><span class="pubdate">2002. </span></p></div><div class="biblioentry"><a name="cit:boost::ref"></a><p>[ref] <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>
|
||||
. </span><span class="pubdate">2002. </span></p></div><div class="biblioentry"><a name="cit:boost::bind"></a><p>[bind] <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>
|
||||
. </span><span class="pubdate">2002. </span></p></div><div class="biblioentry"><a name="cit:boost::function"></a><p>[function] <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>
|
||||
. </span><span class="pubdate">2002. </span></p></div><div class="biblioentry"><a name="cit:fc++"></a><p>[fc++] <span class="title"><I>The FC++ library: Functional Programming in C++</I>. </span><span class="author">Yannis Smaragdakis. </span><span class="author">Brian McNamara. </span><span class="bibliomisc"><a href="http://www.cc.gatech.edu/~yannis/fc++/" target="_top">www.cc.gatech.edu/~yannis/fc++/</a>
|
||||
. </span><span class="pubdate">2002. </span></p></div><div class="biblioentry"><a name="cit:fc++"></a><p>[fc++] <span class="title"><I>The FC++ library: Functional Programming in C++</I>. </span><span class="author">Yannis Smaragdakis. </span><span class="author">Brian McNamara. </span><span class="bibliomisc"><a href="http://www.cc.gatech.edu/~yannis/fc%2B%2B/" target="_top">www.cc.gatech.edu/~yannis/fc++/</a>
|
||||
. </span><span class="pubdate">2002. </span></p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apa.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top">A. Rationale for some of the design decisions </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
|
||||
|
||||
@@ -1156,46 +1156,18 @@ operator defined, can be used as target functions.
|
||||
|
||||
In general, BLL cannot deduce the return type of an arbitrary function object.
|
||||
|
||||
However, there are two methods for giving BLL this capability for a certain
|
||||
However, there is a method for giving BLL this capability for a certain
|
||||
function object class.
|
||||
|
||||
</para>
|
||||
|
||||
<simplesect>
|
||||
|
||||
<title>The result_type typedef</title>
|
||||
|
||||
<para>
|
||||
|
||||
The BLL supports the standard library convention of declaring the return type
|
||||
of a function object with a member typedef named <literal>result_type</literal> in the
|
||||
function object class.
|
||||
|
||||
Here is a simple example:
|
||||
<programlisting>
|
||||
<![CDATA[struct A {
|
||||
typedef B result_type;
|
||||
B operator()(X, Y, Z);
|
||||
};]]>
|
||||
</programlisting>
|
||||
|
||||
If a function object does not define a <literal>result_type</literal> typedef,
|
||||
the method described below (<literal>sig</literal> template)
|
||||
is attempted to resolve the return type of the
|
||||
function object. If a function object defines both <literal>result_type</literal>
|
||||
and <literal>sig</literal>, <literal>result_type</literal> takes precedence.
|
||||
|
||||
</para>
|
||||
|
||||
</simplesect>
|
||||
|
||||
<simplesect>
|
||||
|
||||
<title>The sig template</title>
|
||||
|
||||
<para>
|
||||
Another mechanism that make BLL aware of the return type(s) of a function object is defining
|
||||
member template struct
|
||||
To make BLL aware of the return type(s) of a function object one needs to
|
||||
provide a member template struct
|
||||
<literal><![CDATA[sig<Args>]]></literal> with a typedef
|
||||
<literal>type</literal> that specifies the return type.
|
||||
|
||||
@@ -1214,7 +1186,9 @@ is the function
|
||||
object type itself, and the remaining elements are the types of
|
||||
the arguments, with which the function object is being called.
|
||||
|
||||
This may seem overly complex compared to defining the <literal>result_type</literal> typedef.
|
||||
This may seem overly complex compared to the Standard Library
|
||||
convention for defining the return type of a function
|
||||
object with the <literal>return_type</literal> typedef.
|
||||
Howver, there are two significant restrictions with using just a simple
|
||||
typedef to express the return type:
|
||||
<orderedlist>
|
||||
@@ -1289,6 +1263,27 @@ mechanism first introduced in the FC++ library
|
||||
|
||||
</simplesect>
|
||||
|
||||
<para>
|
||||
Earlier versions of the library supported the Standard Library convention
|
||||
as the default, and required special actions to make the library recognize
|
||||
the <literal>sig</literal> template.
|
||||
Now the BLL has that reversed.
|
||||
|
||||
If one needs to use a functor that adheres to the Standard Library
|
||||
convention in a bind expression, we provide the <literal>std_functor</literal>
|
||||
wrapper, that gives the function object a <literal>sig</literal>
|
||||
template based on the <literal>result_type</literal> typedef.
|
||||
For example:
|
||||
|
||||
<programlisting>
|
||||
<![CDATA[int i = 1;
|
||||
bind(plus<int>(), _1, 1)(i); // error, no sig template
|
||||
bind(std_functor(plus<int>()), _1, 1)(i); // ok]]>
|
||||
</programlisting>
|
||||
|
||||
</para>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
@@ -1862,7 +1857,7 @@ and the effect of evaluating that expression.
|
||||
</row>
|
||||
<row>
|
||||
<entry><literal>destructor()(pa)</literal></entry>
|
||||
<entry><literal>pa->~A()</literal>, where <literal>pa</literal> is of type <literal>A*</literal></entry>
|
||||
<entry><literal>pa.->A()</literal>, where <literal>pa</literal> is of type <literal>A*</literal></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><literal>new_ptr<T>()(<parameter>arg_list</parameter>)</literal></entry>
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
The Boost Lambda Library"><link rel="next" href="ar01s02.html" title="2. Getting Started"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">
|
||||
C++ BOOST
|
||||
|
||||
The Boost Lambda Library</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s02.html">Next</a></td></tr></table><hr></div><div class="article"><div class="titlepage"><div><h1 class="title"><a name="id2733457"></a>
|
||||
<span class="inlinemediaobject"><img src="../../../c++boost.gif" alt="C++ BOOST"></span>
|
||||
The Boost Lambda Library</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ar01s02.html">Next</a></td></tr></table><hr></div><div class="article"><div class="titlepage"><div><h1 class="title"><a name="id2753758"></a>
|
||||
<span class="inlinemediaobject"><img src="../../../c%2B%2Bboost.gif" alt="C++ BOOST"></span>
|
||||
|
||||
The Boost Lambda Library</h1></div><div><p class="copyright">Copyright © 1999-2002 Jaakko Järvi, Gary Powell</p></div><div><div class="legalnotice"><p>
|
||||
The Boost Lambda Library is free software; Permission to copy,
|
||||
use, modify and distribute this software and its documentation is granted, provided this copyright
|
||||
notice appears in all copies.
|
||||
</p></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt>1. <a href="index.html#introduction">In a nutshell</a></dt><dt>2. <a href="ar01s02.html">Getting Started</a></dt><dd><dl><dt>2.1. <a href="ar01s02.html#id2790118">Installing the library</a></dt><dt>2.2. <a href="ar01s02.html#id2741945">Conventions used in this document</a></dt></dl></dd><dt>3. <a href="ar01s03.html">Introduction</a></dt><dd><dl><dt>3.1. <a href="ar01s03.html#id2741999">Motivation</a></dt><dt>3.2. <a href="ar01s03.html#id2742792">Introduction to lambda expressions</a></dt></dl></dd><dt>4. <a href="ar01s04.html">Using the library</a></dt><dd><dl><dt>4.1. <a href="ar01s04.html#sect:introductory_examples">Introductory Examples</a></dt><dt>4.2. <a href="ar01s04.html#sect:parameter_and_return_types">Parameter and return types of lambda functors</a></dt><dt>4.3. <a href="ar01s04.html#sect:actual_arguments_to_lambda_functors">About actual arguments to lambda functors</a></dt><dt>4.4. <a href="ar01s04.html#sect:storing_bound_arguments">Storing bound arguments in lambda functions</a></dt></dl></dd><dt>5. <a href="ar01s05.html">Lambda expressions in details</a></dt><dd><dl><dt>5.1. <a href="ar01s05.html#sect:placeholders">Placeholders</a></dt><dt>5.2. <a href="ar01s05.html#sect:operator_expressions">Operator expressions</a></dt><dt>5.3. <a href="ar01s05.html#sect:bind_expressions">Bind expressions</a></dt><dt>5.4. <a href="ar01s05.html#sect:overriding_deduced_return_type">Overriding the deduced return type</a></dt><dt>5.5. <a href="ar01s05.html#sect:delaying_constants_and_variables">Delaying constants and variables</a></dt><dt>5.6. <a href="ar01s05.html#sect:lambda_expressions_for_control_structures">Lambda expressions for control structures</a></dt><dt>5.7. <a href="ar01s05.html#sect:exceptions">Exceptions</a></dt><dt>5.8. <a href="ar01s05.html#sect:construction_and_destruction">Construction and destruction</a></dt><dt>5.9. <a href="ar01s05.html#id2805507">Special lambda expressions</a></dt><dt>5.10. <a href="ar01s05.html#id2806080">Casts, sizeof and typeid</a></dt><dt>5.11. <a href="ar01s05.html#sect:nested_stl_algorithms">Nesting STL algorithm invocations</a></dt></dl></dd><dt>6. <a href="ar01s06.html">Extending return type deduction system</a></dt><dt>7. <a href="ar01s07.html">Practical considerations</a></dt><dd><dl><dt>7.1. <a href="ar01s07.html#id2807595">Performance</a></dt><dt>7.2. <a href="ar01s07.html#id2808087">About compiling</a></dt><dt>7.3. <a href="ar01s07.html#id2808149">Portability</a></dt></dl></dd><dt>8. <a href="ar01s08.html">Relation to other Boost libraries</a></dt><dd><dl><dt>8.1. <a href="ar01s08.html#id2808540">Boost Function</a></dt><dt>8.2. <a href="ar01s08.html#id2808644">Boost Bind</a></dt></dl></dd><dt>9. <a href="ar01s09.html">Contributors</a></dt><dt>A. <a href="apa.html">Rationale for some of the design decisions</a></dt><dd><dl><dt>1. <a href="apa.html#sect:why_weak_arity">
|
||||
</p></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt>1. <a href="index.html#introduction">In a nutshell</a></dt><dt>2. <a href="ar01s02.html">Getting Started</a></dt><dd><dl><dt>2.1. <a href="ar01s02.html#id2761975">Installing the library</a></dt><dt>2.2. <a href="ar01s02.html#id2762422">Conventions used in this document</a></dt></dl></dd><dt>3. <a href="ar01s03.html">Introduction</a></dt><dd><dl><dt>3.1. <a href="ar01s03.html#id2762467">Motivation</a></dt><dt>3.2. <a href="ar01s03.html#id2762797">Introduction to lambda expressions</a></dt></dl></dd><dt>4. <a href="ar01s04.html">Using the library</a></dt><dd><dl><dt>4.1. <a href="ar01s04.html#sect:introductory_examples">Introductory Examples</a></dt><dt>4.2. <a href="ar01s04.html#sect:parameter_and_return_types">Parameter and return types of lambda functors</a></dt><dt>4.3. <a href="ar01s04.html#sect:actual_arguments_to_lambda_functors">About actual arguments to lambda functors</a></dt><dt>4.4. <a href="ar01s04.html#sect:storing_bound_arguments">Storing bound arguments in lambda functions</a></dt></dl></dd><dt>5. <a href="ar01s05.html">Lambda expressions in details</a></dt><dd><dl><dt>5.1. <a href="ar01s05.html#sect:placeholders">Placeholders</a></dt><dt>5.2. <a href="ar01s05.html#sect:operator_expressions">Operator expressions</a></dt><dt>5.3. <a href="ar01s05.html#sect:bind_expressions">Bind expressions</a></dt><dt>5.4. <a href="ar01s05.html#sect:overriding_deduced_return_type">Overriding the deduced return type</a></dt><dt>5.5. <a href="ar01s05.html#sect:delaying_constants_and_variables">Delaying constants and variables</a></dt><dt>5.6. <a href="ar01s05.html#sect:lambda_expressions_for_control_structures">Lambda expressions for control structures</a></dt><dt>5.7. <a href="ar01s05.html#sect:exceptions">Exceptions</a></dt><dt>5.8. <a href="ar01s05.html#sect:construction_and_destruction">Construction and destruction</a></dt><dt>5.9. <a href="ar01s05.html#id2824949">Special lambda expressions</a></dt><dt>5.10. <a href="ar01s05.html#id2825516">Casts, sizeof and typeid</a></dt><dt>5.11. <a href="ar01s05.html#sect:nested_stl_algorithms">Nesting STL algorithm invocations</a></dt></dl></dd><dt>6. <a href="ar01s06.html">Extending return type deduction system</a></dt><dt>7. <a href="ar01s07.html">Practical considerations</a></dt><dd><dl><dt>7.1. <a href="ar01s07.html#id2827024">Performance</a></dt><dt>7.2. <a href="ar01s07.html#id2827515">About compiling</a></dt><dt>7.3. <a href="ar01s07.html#id2827576">Portability</a></dt></dl></dd><dt>8. <a href="ar01s08.html">Relation to other Boost libraries</a></dt><dd><dl><dt>8.1. <a href="ar01s08.html#id2827965">Boost Function</a></dt><dt>8.2. <a href="ar01s08.html#id2828068">Boost Bind</a></dt></dl></dd><dt>9. <a href="ar01s09.html">Contributors</a></dt><dt>A. <a href="apa.html">Rationale for some of the design decisions</a></dt><dd><dl><dt>1. <a href="apa.html#sect:why_weak_arity">
|
||||
Lambda functor arity
|
||||
</a></dt></dl></dd><dt><a href="bi01.html">Bibliography</a></dt></dl></div><a href="lambda_docs_as_one_file.html" target="_top">Documentation as a one big HTML-file</a><div class="section"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="introduction"></a>1. In a nutshell</h2></div></div><p>
|
||||
|
||||
@@ -34,6 +34,6 @@ In explaining what the library is about, a line of code says more than a thousan
|
||||
The variable <tt>_1</tt> is the parameter of this function, a <span class="emphasis"><i>placeholder</i></span> for the actual argument.
|
||||
Within each iteration of <tt>for_each</tt>, the function is
|
||||
called with an element of <tt>a</tt> as the actual argument.
|
||||
This actual argument is substituted for the placeholder, and the ‘body’ of the function is evaluated.
|
||||
This actual argument is substituted for the placeholder, and the “body” of the function is evaluated.
|
||||
</p><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.
|
||||
</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="ar01s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"> </td><td width="40%" align="right" valign="top"> 2. Getting Started</td></tr></table></div></body></html>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,8 +19,6 @@
|
||||
#include "boost/lambda/detail/is_instance_of.hpp"
|
||||
#include "boost/type_traits/same_traits.hpp"
|
||||
|
||||
#include "boost/indirect_reference.hpp"
|
||||
|
||||
#include <cstddef> // needed for the ptrdiff_t
|
||||
#include <iosfwd> // for istream and ostream
|
||||
|
||||
@@ -223,7 +221,7 @@ namespace detail {
|
||||
|
||||
// A is a nonreference type
|
||||
template <class A> struct contentsof_type {
|
||||
typedef typename boost::indirect_reference<A>::type type;
|
||||
typedef typename std::iterator_traits<A>::reference type;
|
||||
};
|
||||
|
||||
// this is since the nullary () in lambda_functor is always instantiated
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
#ifndef BOOST_LAMBDA_RETURN_TYPE_TRAITS_HPP
|
||||
#define BOOST_LAMBDA_RETURN_TYPE_TRAITS_HPP
|
||||
|
||||
#include "boost/mpl/aux_/has_xxx.hpp"
|
||||
|
||||
#include <cstddef> // needed for the ptrdiff_t
|
||||
|
||||
namespace boost {
|
||||
@@ -241,25 +239,6 @@ struct return_type_N<function_action<I, Ret>, Args> {
|
||||
typedef Ret type;
|
||||
};
|
||||
|
||||
// ::result_type support
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
|
||||
|
||||
template<class F> struct get_result_type
|
||||
{
|
||||
typedef typename F::result_type type;
|
||||
};
|
||||
|
||||
template<class F, class A> struct get_sig
|
||||
{
|
||||
typedef typename function_adaptor<F>::template sig<A>::type type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// Ret is detail::unspecified, so try to deduce return type
|
||||
template<int I, class Args>
|
||||
struct return_type_N<function_action<I, detail::unspecified>, Args > {
|
||||
@@ -272,11 +251,7 @@ struct return_type_N<function_action<I, detail::unspecified>, Args > {
|
||||
public:
|
||||
// pass the function to function_adaptor, and get the return type from
|
||||
// that
|
||||
typedef typename detail::IF<
|
||||
detail::has_result_type<plain_Func>::value,
|
||||
detail::get_result_type<plain_Func>,
|
||||
detail::get_sig<plain_Func, Args>
|
||||
>::RET::type type;
|
||||
typedef typename function_adaptor<plain_Func>::template sig<Args>::type type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user