|
Boost Users : |
From: Simon Buchan (simon_at_[hidden])
Date: 2005-09-22 03:44:08
Bjorn.Karlsson_at_[hidden] wrote:
> Hello Tom,
>
> -----Original Message-----
> From: tom gee [mailto:rockonedge_at_[hidden]]
> Subject: [Boost-users] A question about boost::lambda::if_ behavior
>
>
>>Can anyone please explain this code:
>
> [snip]
>
> The problem is that the expression std::cout << constant("Bingo:<") is
> evaluated immediately. Why? Because it's not a lambda expression. You have
> two options that will help you turn your if-branch into a lambda expression;
> either use boost::lambda::var or boost::lambda::constant.
>
> Using boost::lambda::var:
>
> std::for_each(setFinalVal.begin(),setFinalVal.end(),
> (std::cout << _1 << " ", if_(_1 < 24.000001 && _1 > 23.999999)
> [var(std::cout) << "Bingo:<" << _1 << ">"]));
>
> Using boost::lambda::constant:
>
> std::for_each(setFinalVal.begin(),setFinalVal.end(),
> (std::cout << _1 << " ", if_(_1 < 24.000001 && _1 > 23.999999)
> [std::cout << constant("Bingo:<") << _1 << ">"]));
>
>
> Cheers,
> Bjorn Karlsson
constant should be better (lower overhead, conceptually closer),
but no biggy. I beleive this is the No.1 FAQ, is it not?
(PS: why does not the lambda docs say in the function call overload
section to use BLL's bind? It took me AGES to figure out how to do
that!)
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