Subject: Re: phoenix lambda-lambda for_each example
From: Joel de Guzman <[email-masked]>
To: David Abrahams <[email-masked]>
Cc: Noah Stein <[email-masked]>, [email-masked], Aleksey Gurtovoy <[email-masked]>, Jaakko Jarvi <[email-masked]>
Date: Wed, 03 Mar 2004 11:22:50 +0800

David Abrahams wrote:

> Joel de Guzman <[email-masked]> writes:
> 
> 
>>Consider this:
>>
>>     std::vector<std::vector<int> > v;
>>     ...
>>     for_each(arg1, for_each(arg1, cout << arg1 << ' '))
>>     (v);
>>
>>Prints all the elements of v.
> 
> 
> Actually that case is kind of strange.  I think in MPL we're deciding
> that you need to do something like:
> 
> 
>   for_each(arg1, function(for_each(arg1, cout << arg1 << ' ')))(v)
> 
> to prevent v from being substituted into *all* of the arg1s.

I thought about that too. Upon meditation, I realized it is
not necessary. In this case, Phoenix has scope! That's why I
wrote the title "lamda-lambda". Consider:

     std::vector<std::vector<int> > v;
     ...
     for_each(arg1, for_each(arg1, cout << arg1 << ' '))
     (v);

* The first arg1 gets a std::vector<std::vector<int> >
* The second arg1 gets a std::vector<int>
* the third arg1 gets an int.

Each lambda has its own scope. Try the attached example, if you
are not convinced.

Cheers,
-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net