Boost logo

Boost Users :

From: Hendrik Belitz (hbelitz_at_[hidden])
Date: 2007-08-13 08:17:37


Hello,
 
I'm rather stucked in using lambda expressions for a presumably simple task.
Suppose I have objects with a member function
bool is_empty() const;
stored in a vector: I want to count the number of objects for which their
member functions returns false, which is simple, but not elegant to achieve
by
size_t sum = 0;
for( Foo::const_iterator it = vec.begin(); it != vec.end(); ++it )
   if ( it->is_empty() == false ) sum++;

I want to exchange this for a lambda expression, and came up with the
following after some thinking.

for_each( begin(), end(), if_then( !(_1 ->* &GridCell::is_empty)(),
var(sum)++ ) );

This is still wrong and leads to two error messages:
error C2784: 'const
boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lamb
da::logical_action<Action>,boost::tuples::tuple<boost::lambda::lambda_functo
r<T>>>> boost::lambda::operator !(const boost::lambda::lambda_functor<T> &)'
: could not deduce template argument for 'const
boost::lambda::lambda_functor<T> &' from 'boost::tuples::null_type'
error C2675: unary '!' : 'boost::tuples::null_type' does not define this
operator or a conversion to a type acceptable to the predefined operator
 
Could anyone tell how to get this working?
 
Regards
 Hendrik
 

--
Hendrik Belitz
ISD Software und Systeme GmbH
Hauert 4
D - 44227 Dortmund
Germany
 
Fon: +49 (0)231/97 93-0
Fax: +49 (0)231/97 93-101
Mail:  <mailto:hBelitz_at_[hidden]> hBelitz_at_[hidden]
Internet:  <http://www.isdcad.de/> www.isdcad.de
 
Geschäftsführung: Günter Flassig (Vors.), Dr. Jörg Ruhwedel
Sitz Dortmund, Amtsgericht Dortmund HRB 4601
 



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