
On 30.03.2012, at 19:19, 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?
Calling member functions doesn't work that way with lambdas. You have to use boost::lambda::bind. http://www.boost.org/doc/libs/1_49_0/doc/html/lambda/le_in_details.html#lamb... So for your code: 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