On Fri, Feb 5, 2010 at 4:52 PM, Archie14
Nat Goodspeed
writes: Archie14 wrote:
What I am trying to achieve is to stop for_each if "getParamValue" returns false. However I can't find a way to use "return" in the second part of boost::lambda::if_, so I am using a dummy var "a" to check it after the
completes.
My question is: what is the right way to use lambda control structure in
loop this
case?
Maybe you want std::find_if instead of std::for_each?
Well, what I have to do is to iterate through each and every element of the container and calculate validity of the element. If current element fails the test I don't have to continue further. I don't think that std::find_if would work in this case.
My question is more to how the control structure of "lambda" library works in respect to "return" or "brake" in the cycle.
Well you could return early, but it would not help since the lambda function is called for each element, returning early would just finish execution of the current element work. What you probably want to do is either find_if (which should still work for your situation), or throw an exception (much easier to do with Boost.Phoenix instead of Boost.Lambda, Phoenix can do everything Lambda does and a great deal more).