Boost logo

Boost :

Subject: Re: [boost] Case study: Boost.Local versus Boost.Phoenix
From: Artyom (artyomtnk_at_[hidden])
Date: 2011-02-04 10:20:52


> It's not just you.
> I've made a habit (which have been widely adapted by others at my workplace)
> to make local lambdas like this:
>
> void my_function()
> {
> foo_type foo;
> bar_type bar;
>
> struct {
> foo_type &foo_;
> bar_type &bar_;
> void operator()(a_type a) const
> {
> foo_(a);
> bar_(a);
> }
> } lambda = { foo, bar} ;
>
> for_each(as.begin(),as.end(),lambda);
>
> }
>
> I don't know if that's standard compliant, but works perfectly fine in MSVC.
> I like the {} initializer, so I don't need to write a boilerplate
> constructor.
>

AFAIK it is not standard compliant and gcc does not accept this (with
combination
of for_each of other situations);

But

   struct lambda_type {
        foo_type &foo_;
       bar_type &bar_;
        void operator()(a_type a) const
       {
             foo_(a);
             bar_(a);
       }
    };

  void my_function()
  {
    foo_type foo;
    bar_type bar;
 
   lambda_type lambda = { foo, bar} ;
 
    for_each(as.begin(),as.end(),lambda);
 
  }

Is more then fine and this is what I usually use.

      


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