Boost logo

Boost Users :

From: Bjorn.Karlsson_at_[hidden]
Date: 2005-09-22 03:12:00


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


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