Boost logo

Boost Users :

Subject: Re: [Boost-users] [bind] How do I....?
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-08-18 14:13:01


On Tue, Aug 18, 2009 at 11:10 AM, Michael
Caisse<boost_at_[hidden]> wrote:
> Robert Jones wrote:
>>
>> 2009/8/18 Björn Karlsson <Bjorn.Karlsson_at_[hidden]
>> <mailto:Bjorn.Karlsson_at_[hidden]>>
>>
>>
>>
>>    2) Use Boost.Lambda's bind() and dereference the placeholder
>>    directly in the bind expression.
>>
>>     for_each(vec.begin(), vec.end(), bind(&foo, *_1));
>>
>> Much as I like Lambda for virgin code, in my work code base there's a very
>> visible inclusion
>> of Boost.Bind, with placeholders in the global namespace. I've concluded
>> that the pain of clashing
>> placeholders just isn't worth it, so I steer clear of Lambda now.
>>
>> Thanks Bjorn.
>>
>>  - Rob.
>
> Rob -
>
> Let me suggest Boost.Phoenix. Phoenix is an amazingly powerful library that
> will
> handle all of your bind and lambda needs. You also wont suffer from the
> plagued
> global namespace fiasco by mixing Boost.Bind and Boost.Lambda.
>
> Your example with Phoenix:
>
>
> #include <vector>
> #include <algorithm>
> #include <boost/shared_ptr.hpp>
> #include <boost/spirit/home/phoenix/core.hpp>
> #include <boost/spirit/home/phoenix/operator.hpp>
> #include <boost/spirit/home/phoenix/bind/bind_function.hpp>
>
> struct A {};
>
> void foo( const A& ) {}
>
> int main()
> {
>  using namespace boost::phoenix;
>  using namespace boost::phoenix::arg_names;
>
>  std::vector< boost::shared_ptr< A > > vec;
>  vec.push_back( boost::shared_ptr< A >( new A ) );
>
>  std::for_each( vec.begin(), vec.end(),
>                 bind( &foo, *arg1 ) );
>  return 0;
> }
>
>
> I hope this helps out.

This is another vote for Boost.Phoenix2, its bind replaces all
possible uses I have ever seen of Boost.Bind or Boost.Lambda::bind and
in an easier way.


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