|
Boost Users : |
Subject: Re: [Boost-users] [Bind] Understanding protect
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2012-03-28 05:04:54
On 03/28/2012 09:47 AM, Robert Jones wrote:
> On Tue, Mar 27, 2012 at 8:24 PM, Thomas Heller
> <thom.heller_at_[hidden]>wrote:
>
>> You might also want to consider phoenix::lambda, it is like protect, but
>> slightly more powerful.
>> your example would then read:
>> #include<boost/phoenix.hpp>
>>
>> int main( )
>> {
>> std::vector<int> v;
>> v += 0,1,2,3,4,5,6;
>> using boost::phoenix::bind;
>> using boost::phoenix::lambda;
>> using boost::phoenix::placeholders::**_1;
>> using boost::phoenix::local_names::_**1;
>>
>> for_each( v.begin( ), v.end( ),
>> bind(g, lambda(_a = _1)[bind(f, _a)]));
>>
>> return 0;
>> }
>>
>>
> Please don't remind me! I'd love to, but I'm stuck in the antediluvian days
> of 1.37!
>
> - Rob.
Ouch. In that case, protect should work just fine.
Here is a complete and working example:
https://gist.github.com/2224915
Note that I had to get rid of the template. free template functions are
a pain to bind, you would need to somehow cast it to the correct
function type, which is unnecessarily clutter, and gets worse in your
case. I suggest using functors, there, templates are not a problem at all:
<https://gist.github.com/2224920>
<https://gist.github.com/2224920>https://gist.github.com/2224918
To sketch the full picture, phoenix is able to handle that in a saner
fashion (sorry for the plug, take it as future reference, I don't want
to make your life miserable):
https://gist.github.com/2224920
Note that in the phoenix solution, bind is not necessary anymore.
Phoenix is able to adapt (even templated) functions to know how to
lazily evaluate them.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net