Boost logo

Boost :

From: Jaakko Jarvi (jajarvi_at_[hidden])
Date: 2003-05-30 13:30:49


The bug is in the documentation.
All of the compilers are right. The complier can choose to evaluate
i=2 before _1+i which results in the lambda functor

  _1 + 2

or _1+i before i=2 which gives

  _1 + 1

Anyway, the point of the documentation was to say that the lambda functor
stores the value of i at the time of creating the lambda functor, and
the actual argument to later replace _1 will be passed by reference.
So no side effects via the stored arguments.
The example in the docs is just badly chosen.

  Jaakko

On Fri, 30 May 2003, firingme wrote:

> consider the following code :
>
> test.cpp
> *************************************************************
> #include <boost/lambda/lambda.hpp>
> #include <boost/lambda/bind.hpp>
>
> #include <list>
> #include <algorithm>
> #include <iostream>
> #include <vector>
>
> using namespace std ;
> using namespace boost ;
> using namespace boost::lambda;
>
> int main(){
> int i = 1 ;
> cout << ( _1+i)(i=2) << endl;
> }
> *************************************************************
>
> Result Table:
> *************************************************************
> Compiler Result
>
> VC7.1 4
> GCC3.2.3 ( MingW versiong ) 4
> GCC3.3 (i686-pc-cygwin) 3
>
> as in lambda's doc , the result should be 3 .
>
> Any help is welcome
>
>
> thx
>
>
>
>
>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk