Boost logo

Boost Users :

From: Haroon Khan (haroon.khan_at_[hidden])
Date: 2006-11-27 02:14:53


 Hi,
 I'm experimenting with the boost lambda library, and I wrote the
 following code, to go through the vector of numbers and print out
 statements if the number is greater than 5 or less than 5

     int a[]={1,2,3,4,5,6,7,8,9,10,10,9,8,4,7,6,5,4,3,3,1};
     std::vector<int> v(a,a+sizeof(a)/sizeof(int));
     std::for_each
             ( v.begin()
             , v.end()
             , (if_(_1<5)[
                     std::cout<<var((boost::format("%d is less than
5\n")%_1).str())
                 ].else_[
                     std::cout<<var((boost::format("%d is greater than
5\n")%_1).str())
                 ]) );

 The boost::basic_format::operator % code gives an
 assertion since
 the object that is being passed is the placeholder object, and not
 the current value. Is there a correct way of doing this?

 Thanks, Haroon


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