|
Boost Users : |
From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2007-05-19 11:23:04
On 19/05/07, Stephen Torri <storri_at_[hidden]> wrote:
> On Sat, 2007-05-19 at 09:34 -0400, Nat Goodspeed wrote:
> > > -----Original Message-----
> > > From: boost-users-bounces_at_[hidden] [mailto:boost-users-
> > > bounces_at_[hidden]] On Behalf Of Stephen Torri
> > > Sent: Friday, May 18, 2007 9:01 PM
> > > To: boost-users
> > > Subject: [Boost-users] Converting loop to using boost::lambda
> > > where containers has boost::shared_ptrs
> > >
> > > My idea was to do:
> > >
> > > std::for_each ( m_data.begin(),
> > > m_data.end(),
> > > output << (_1 ->* &Verification_Type_Info::to_String) (
> > > new_indent_limit ) );
> >
> > [Nat] I think the construct you want will look more like (untested):
> >
> > std::for_each(m_data.begin(), m_data.end(),
> > output << boost::bind(&Verification_Type_Info::to_String,
> > _1,
> > new_indent_limit));
>
> Its close but not quite. I get an error message that _1 is ambiguous
>
> Append_Frame.cpp:48: error: reference to '_1' is ambiguous
> /usr/include/boost/lambda/core.hpp:69: error: candidates are: const boost::lambda::placeholder1_type& boost::lambda::<unnamed>::_1
> /usr/include/boost/bind/placeholders.hpp:54: error: boost::arg<1> <unnamed>::_1
>
> Stephen
Nat's using Boost.Bind, not the bind in Boost.Lambda - they both
define _1 as a placeholder, so they clash...
Using bind from Boost.Lambda, you'll need nested binds to cope with shared_ptr:
using namespace boost::lambda;
std::for_each(m_data.begin(), m_data.end(),
output << bind(&Verification_Type_Info::to_String,
bind(boost::shared_ptr<Verification_Type_Info>::get, _1),
new_indent_limit));
Totally untested....
HTH
Stuart Dootson
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