Boost logo

Boost Users :

Subject: Re: [Boost-users] lambda control structures
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2010-02-05 19:50:45


On Fri, Feb 5, 2010 at 4:52 PM, Archie14 <admin_at_[hidden]> wrote:
> Nat Goodspeed <nat <at> lindenlab.com> 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
> loop
>> > completes.
>> >
>> > My question is: what is the right way to use lambda control structure in
> 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).


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