|
Boost Users : |
Subject: Re: [Boost-users] Boost.lambda: can I do this with a lambda function (multiplestatements?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-02-03 13:48:10
AMDG
Joost Kraaijeveld wrote:
> I want to embed some debug printing in a lambda function which is a
> predicate used to remove elements from a vector like this:
>
> collection.erase( std::remove_if(
> collection.begin(),
> collection.end(),
> boost::lambda::if_then_else_return(
> boost::lambda::_1 <= "s5", // if
> (std::cout << "deleted: " << boost::lambda::_1, true), // then
> (std::cout << "not deleted: " << boost::lambda::_1, false ))), // else
> collection.end());
>
>
> This actually compiles, runs and removes all the right elements but it
> does not print for every element it is checking.
>
> It just prints "not deleted: deleted: s4s5s6s8" , the last string being
> all the elements of the collection.
>
> Is what I want possible and if so how?
>
std::cout << "deleted" is executed immediately. (This is
a limitation of expression templates. It can't be made to work)
Try
std::cout << boost::lambda::constant("deleted") << ...
similarly for not deleted.
In Christ,
Steven Watanabe
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