Boost logo

Boost :

From: Darren Cook (darren_at_[hidden])
Date: 2004-02-16 07:19:07


Hi,
I've read the lambda sections of the FC++ docs, and the paper on the
subject, and am a bit confused how to use it. Could you show the FC++
equivalents of these BLL examples:

1. (from the paper)
   int a[]={5,3,8,4};
   std::for_each(a,a+4,std::cout<<_1<<"\n");

2.
   int a[]={5,3,8,4};
   std::for_each(a,a+4,std::cout<<constant("v=")<<_1<<"\n");

3. (a vector of MyClass pointers)
     std::for_each(
        tests.begin(),
        tests.end(),
        bind(&MyClass::save,_1,f)
        );

4.
     std::for_each(
        tests.begin(),
        tests.end(),
        bind(delete_ptr(), _1)
        );

5. (in a spirit parser)
     Node= +(
        (+range_p('A','Z'))[bind(&MyClass::on_name, this, _1,_2)]
>> +(
        ch_p('[')
>> (*(anychar_p-']'))[bind(&MyClass::on_value, this, _1,_2)]
>> ch_p(']')
        )
        );

Darren

*: For each I'm doing something like:
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/lambda/construct.hpp>

using namespace boost::lambda;


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