Boost logo

Boost Users :

Subject: Re: [Boost-users] Lambda and placeholders
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2012-03-30 14:16:57

On 03/30/2012 07:19 PM, Sven Bauhan wrote:
> Hi,
> I just tried to use boost::lambda to prevent from creating an extra Functor
> class just for one call.
> This is the code I tried:
> std::deque<LightningSlice>::const_iterator l
> = std::find_if( m_lightnings.begin(), m_lightnings.end(),
> boost::lambda::_1.timeslice().contains(time_) );
> with
> typedef std::deque<LightningSlice> LightningQueue;
> LightningQueue m_lightnings; //!< The lightnings in timeslices
> const boost::posix_time::time_period& LightningSlice::timeslice() const
> {
> return this->m_period;
> }
> Then I get the error:
> ../LightningIndex.cpp:38: error: 'const struct
> boost::lambda::lambda_functor<boost::lambda::placeholder<1> >' has no member
> named 'timeslice'
> What did I wrong?

The type of the placeholder is completely different from the type the
placeholder will be eventually be replaced with. This in fact could be
any type in the world. What you need to do is bind it:

bind( // We want to bind the result of the innermost bind to another
       // function
   , bind(
         // We want to bind the timeslice function to the first argument
         // passed
       , _1

The flavor of bind you want to use is not important. There are currently
3 possibilities in boost (and a 4th if you use C++11):

Boost.Bind is really just to bind functions. Lambda and Phoenix allow to
build more sophisticated unnamed functions. Phoenix is the newest
> Thanks,
> Sven
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at