From 0323ca187645340dfd4a0aeb99f0eebb2ef6b8ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20J=C3=A4rvi?= Date: Mon, 30 Sep 2002 20:40:07 +0000 Subject: [PATCH] fixed a bug in example code [SVN r15576] --- doc/apa.html | 2 +- doc/ar01s04.html | 2 +- doc/ar01s05.html | 21 ++++++++++---------- doc/ar01s07.html | 4 ++-- doc/ar01s08.html | 12 ++++++------ doc/bi01.html | 2 +- doc/detail/lambda_doc.xml | 25 ++++++++++++------------ doc/index.html | 2 +- doc/lambda_docs_as_one_file.html | 33 ++++++++++++++++---------------- 9 files changed, 53 insertions(+), 50 deletions(-) diff --git a/doc/apa.html b/doc/apa.html index 44b5811..cb730e0 100644 --- a/doc/apa.html +++ b/doc/apa.html @@ -5,7 +5,7 @@ The Boost Lambda Library">

A. Rationale for some of the design decisions

1. + The Boost Lambda Library">

A. Rationale for some of the design decisions

1. Lambda functor arity

The highest placeholder index in a lambda expression determines the arity of the resulting function object. diff --git a/doc/ar01s04.html b/doc/ar01s04.html index f055718..bc8833d 100644 --- a/doc/ar01s04.html +++ b/doc/ar01s04.html @@ -25,7 +25,7 @@ for_each(v.begin(), v.end(), _1 = 1); Next, we create a container of pointers and make them point to the elements in the first container v:

-list<int*> vp(10); 
+vector<int*> vp(10); 
 transform(v.begin(), v.end(), vp.begin(), &_1);
The expression &_1 creates a function object for getting the address of each element in v. diff --git a/doc/ar01s05.html b/doc/ar01s05.html index 027267a..8f92762 100644 --- a/doc/ar01s05.html +++ b/doc/ar01s05.html @@ -533,7 +533,7 @@ By using var to make index a lambda expression, we get the des In sum, var(x) creates a nullary lambda functor, which stores a reference to the variable x. When the lambda functor is invoked, a reference to x is returned. -

Naming delayed constants and variables

+

Naming delayed constants and variables

It is possible to predefine and name a delayed variable or constant outside a lambda expression. The templates var_type, constant_type and constant_ref_type serve for this purpose. @@ -635,13 +635,7 @@ for_each(a, a+5, The BLL supports an alternative syntax for control expressions, suggested by Joel de Guzmann. By overloading the operator[] we can -get a closer resemblance with the built-in control structures. -For example, using this syntax the if_then example above -can be written as: -

-for_each(a.begin(), a.end(), 
-         if(_1 % 2 == 0)[ cout << _1 ])  
-
+get a closer resemblance with the built-in control structures:
 if_(condition)[then_part]
@@ -651,6 +645,13 @@ do_[body].while_(condition)
 for_(init, condition, increment)[body]
 
+For example, using this syntax the if_then example above +can be written as: +
+for_each(a.begin(), a.end(), 
+         if(_1 % 2 == 0)[ cout << _1 ])  
+
+ As more experience is gained, we may end up deprecating one or the other of these syntaces. @@ -975,7 +976,7 @@ int nested(const F& f) { } -

5.9.1.2. Protect

+

5.9.1.2. Protect

The protect function is related to unlambda. It is also used to prevent the argument substitution taking place, @@ -1109,7 +1110,7 @@ int count = 0; for_each(a.begin(), a.end(), if_then(ll_dynamic_cast<derived*>(_1), ++var(count))); -

5.10.2. Sizeof and typeid

+

5.10.2. Sizeof and typeid

The BLL counterparts for these expressions are named ll_sizeof and ll_typeid. diff --git a/doc/ar01s07.html b/doc/ar01s07.html index 8eb44a3..2b74bc5 100644 --- a/doc/ar01s07.html +++ b/doc/ar01s07.html @@ -5,7 +5,7 @@ The Boost Lambda Library">

7. Practical considerations

7.1. Performance

In theory, all overhead of using STL algorithms and lambda functors + The Boost Lambda Library">

7. Practical considerations

7.1. Performance

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"><

Some additional performance testing with an earlier version of the library is described [Jär00]. -

7.2. About compiling

The BLL uses templates rather heavily, performing numerous recursive instantiations of the same templates. +

7.2. About compiling

The BLL uses templates rather heavily, performing numerous recursive instantiations of the same templates. This has (at least) three implications:

  • While it is possible to write incredibly complex lambda expressions, it probably isn't a good idea. diff --git a/doc/ar01s08.html b/doc/ar01s08.html index 0a6b004..d7aae8d 100644 --- a/doc/ar01s08.html +++ b/doc/ar01s08.html @@ -5,7 +5,7 @@ The Boost Lambda Library">

    8. Relation to other Boost libraries

    8.1. Boost Function

    Sometimes it is convenient to store lambda functors in variables. + The Boost Lambda Library">

    8. Relation to other Boost libraries

    8.1. Boost Function

    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. The Boost Function library [function] defines wrappers for arbitrary function objects, for example lambda functors; and these wrappers have types that are easy to type out. @@ -13,14 +13,14 @@ lambda functors; and these wrappers have types that are easy to type out. For example:

    -boost::function<int, int, int> f = _1 + _2;
    -boost::function<int&, int&> g = unlambda(_1 += 10);
    +boost::function<int(int, int)> f = _1 + _2;
    +boost::function<int&(int&)> g = (_1 += 10);
     int i = 1, j = 2;
     f(i); // returns 3
     g(i); // sets i to = 11;
     
    -The return and parameter types of the wrapped function object must be written explicilty as template arguments to the wrapper template boost::function; even when lambda functors, which otherwise have generic parameters, are wrapped. +The return and parameter types of the wrapped function object must be written explicilty as the template argument to the wrapper template boost::function; even when lambda functors, which otherwise have generic parameters, are wrapped. Wrapping a function object with boost::function introduces a performance cost comparable to virtual function dispatch, though virtual functions are not actually used. Note that storing lambda functors inside boost::function @@ -38,13 +38,13 @@ For example:
     int* sum = new int();
     *sum = 0;
    -boost::function<int&, int> counter = *sum += _1;
    +boost::function<int&(int)> counter = *sum += _1;
     counter(5); // ok, *sum = 5;
     delete sum; 
     counter(3); // error, *sum does not exist anymore
     
    -

    8.2. Boost Bind

    +

    8.2. Boost Bind

    The Boost Bind [bind] 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. diff --git a/doc/bi01.html b/doc/bi01.html index b0cbe63..82bb67c 100644 --- a/doc/bi01.html +++ b/doc/bi01.html @@ -5,7 +5,7 @@ The Boost Lambda Library">

    Bibliography

    [STL94] A. A. Stepanov and M. Lee. The Standard Template Library. Hewlett-Packard Laboratories. 1994. + The Boost Lambda Library">

    Bibliography

    [STL94] A. A. Stepanov and M. Lee. The Standard Template Library. Hewlett-Packard Laboratories. 1994. www.hpl.hp.com/techreports .

    [SGI02] The SGI Standard Template Library. 2002. www.sgi.com/tech/stl/.

    [C++98] International Standard, Programming Languages – C++. ISO/IEC:14882. 1998.

    [Jär99]



    1. In a nutshell

    diff --git a/doc/lambda_docs_as_one_file.html b/doc/lambda_docs_as_one_file.html index a83ca4b..b2e030d 100644 --- a/doc/lambda_docs_as_one_file.html +++ b/doc/lambda_docs_as_one_file.html @@ -259,7 +259,7 @@ for_each(v.begin(), v.end(), _1 = 1); Next, we create a container of pointers and make them point to the elements in the first container v:

    -list<int*> vp(10); 
    +vector<int*> vp(10); 
     transform(v.begin(), v.end(), vp.begin(), &_1);
    The expression &_1 creates a function object for getting the address of each element in v. @@ -997,7 +997,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); -

    About assignment and subscript operators

    +

    About assignment and subscript operators

    As described in Section 5.2.2, assignment and subscripting operators are always defined as member functions. This means, that for expressions of the form x = y or x[y] to be interpreted as lambda expressions, the left-hand operand x must be a lambda expression. @@ -1070,13 +1070,7 @@ for_each(a, a+5, The BLL supports an alternative syntax for control expressions, suggested by Joel de Guzmann. By overloading the operator[] we can -get a closer resemblance with the built-in control structures. -For example, using this syntax the if_then example above -can be written as: -

    -for_each(a.begin(), a.end(), 
    -         if(_1 % 2 == 0)[ cout << _1 ])  
    -
    +get a closer resemblance with the built-in control structures:
     if_(condition)[then_part]
    @@ -1086,6 +1080,13 @@ do_[body].while_(condition)
     for_(init, condition, increment)[body]
     
    +For example, using this syntax the if_then example above +can be written as: +
    +for_each(a.begin(), a.end(), 
    +         if(_1 % 2 == 0)[ cout << _1 ])  
    +
    + As more experience is gained, we may end up deprecating one or the other of these syntaces. @@ -1284,7 +1285,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. -

    Table 1. Construction and destruction related function objects.

    Function object callWrapped expression
    constructor<T>()(arg_list)T(arg_list)
    destructor()(a)a.~A(), where a is of type A
    destructor()(pa)pa.->A(), where pa is of type A*
    new_ptr<T>()(arg_list)new T(arg_list)
    new_array<T>()(sz)new T[sz]
    delete_ptr()(p)delete p
    delete_array()(p)delete p[]

    5.9. Special lambda expressions

    5.9.1. Preventing argument substitution

    +

    Table 1. Construction and destruction related function objects.

    Function object callWrapped expression
    constructor<T>()(arg_list)T(arg_list)
    destructor()(a)a.~A(), where a is of type A
    destructor()(pa)pa.->A(), where pa is of type A*
    new_ptr<T>()(arg_list)new T(arg_list)
    new_array<T>()(sz)new T[sz]
    delete_ptr()(p)delete p
    delete_array()(p)delete p[]

    5.9. Special lambda expressions

    5.9.1. Preventing argument substitution

    When a lambda functor is called, the default behavior is to substitute the actual arguments for the placeholders within all subexpressions. @@ -1932,7 +1933,7 @@ The BLL works with the following compilers, that is, the compilers are capable o )

-

7.3.1. Test coverage

The following list describes the test files included and the features that each file covers: +

7.3.1. Test coverage

The following list describes the test files included and the features that each file covers:

  • bind_tests_simple.cpp : Bind expressions of different arities and types of target functions: function pointers, function objects and member functions. @@ -1986,14 +1987,14 @@ lambda functors; and these wrappers have types that are easy to type out. For example:

    -boost::function<int, int, int> f = _1 + _2;
    -boost::function<int&, int&> g = unlambda(_1 += 10);
    +boost::function<int(int, int)> f = _1 + _2;
    +boost::function<int&(int&)> g = (_1 += 10);
     int i = 1, j = 2;
     f(i); // returns 3
     g(i); // sets i to = 11;
     
    -The return and parameter types of the wrapped function object must be written explicilty as template arguments to the wrapper template boost::function; even when lambda functors, which otherwise have generic parameters, are wrapped. +The return and parameter types of the wrapped function object must be written explicilty as the template argument to the wrapper template boost::function; even when lambda functors, which otherwise have generic parameters, are wrapped. Wrapping a function object with boost::function introduces a performance cost comparable to virtual function dispatch, though virtual functions are not actually used. Note that storing lambda functors inside boost::function @@ -2011,7 +2012,7 @@ For example:
     int* sum = new int();
     *sum = 0;
    -boost::function<int&, int> counter = *sum += _1;
    +boost::function<int&(int)> counter = *sum += _1;
     counter(5); // ok, *sum = 5;
     delete sum; 
     counter(3); // error, *sum does not exist anymore
    @@ -2036,7 +2037,7 @@ a larger set of compilers.
     

    The following two sections describe what are the semantic differences between the bind expressions in BB and BLL. -

    8.2.1. First argument of bind expression

    +

    8.2.1. First argument of bind expression

    In BB the first argument of the bind expression, the target function, is treated differently from the other arguments,