Boost logo

Boost Users :

Subject: Re: [Boost-users] Lambda and placeholders
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2012-04-02 07:12:30


On 04/02/2012 09:52 AM, Sven Bauhan wrote:
>> namespace ll = boost::lambda;
>> ... = std::find_if(..., ll::bind(&Timeslice::contains,
>> ll::bind(&LightningSlice::timeslice, ll::_1), time_));
>>
>> Yes, it's ugly. Unfortunately, you can't really improve on it.
>>
>> Sebastian
>> _______________________________________________
> Thanks,
>
> I tried this suggestion:
>
> #include<boost/lambda/bind.hpp>
> namespace ll = boost::lambda;
>
> LightningQueue::const_iterator l
> = std::find_if( m_lightnings.begin(), m_lightnings.end(),
> bind(&boost::posix_time::time_period::contains,
> ll::bind(&LightningSlice::timeslice, ll::_1 ), time_
> ) );
>
> But then I got this error message:
>
> ../LightningIndex.cpp: In member function 'weather::LightningSlice
> weather::LightningIndex::getLightningSlice(boost::posix_time::ptime)':
> ../LightningIndex.cpp:40: error: no matching function for call to
> 'bind(<unresolved overloaded function type>, const
> boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2,
> boost::lambda::function_action<2, boost::lambda::detail::unspecified> >,
> boost::tuples::tuple<const boost::posix_time::time_period&
> (weather::LightningSlice::* const)()const, const
> boost::lambda::lambda_functor<boost::lambda::placeholder<1> >,
> boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type,
> boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type,
> boost::tuples::null_type, boost::tuples::null_type> > >,
> boost::posix_time::ptime&)'
>
> This is even more confusion than the first error message.
The problem is that boost::posix_time::time_period::contains is
overloaded. Thus the compiler can not decide which function address you
mean.
The solution I usually go with is the following:

bool (boost::posix_time::time_period::*f)(boost::posix_time::time_period
const &) const = &boost::posix_time::time_period::contains;

or:

bool (boost::posix_time::time_period::*f)(boost::posix_time::ptime const
&) const = &boost::posix_time::time_period::contains;

Depending on what type time_ actually is ...

and then continue with:

LightningQueue::const_iterator l
                = std::find_if( m_lightnings.begin(), m_lightnings.end(),
                                bind(f,
                                ll::bind(&LightningSlice::timeslice, ll::_1 ), time_
                        ) );

> Greetings, Sven
> _______________________________________________
> 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