Velocity Reviews > C++ > lambda recursion

# lambda recursion

Chris Forone
Guest
Posts: n/a

 04-29-2013
Am 29.04.2013 13:41, schrieb Ike Naar:
> On 2013-04-29, Chris Forone <(E-Mail Removed)> wrote:
>> Am 29.04.2013 12:40, schrieb Chris Forone:
>>> [snip]
>>> // five 3d vectors (xyz)
>>> std::array<float, 5 * 3> store =
>>> {
>>> 1.0f, 0.0f, 0.0f,
>>> 0.0f, 0.0f, 0.0f,
>>> 0.0f, 0.0f, 0.0f,
>>> 0.0f, 0.0f, 0.0f,
>>> 0.0f, 1.0f, 0.0f
>>> };
>>> [snip]
>>> split(0, 12);
>>> [snip]

>>
>> if (first + 3 < second) does it... sorry for that

>
> Are you sure?
> Consider, for instance, what happens when the array has 4*3 elements
> and split(0,9) is called (hint: at the next level of recursion,
> split(0,4) and split(4,9) will be called).
> It looks like you need to calculate middle in such a way that it
> is a multiple of 3.
>

yes, i know this. i am only experimenting...

cheers, chris

Chris Forone
Guest
Posts: n/a

 04-30-2013
Am 29.04.2013 16:49, schrieb Andy Champ:
> On 29/04/2013 12:15, Chris Forone wrote:
>> if (first + 3 < second) does it... sorry for that

>
> Not for me. You get a stack overflow from infinite recursion.
>
> When called with (4,12) it passes the test. Middle is set to 4, so the
> second recursive split call is with parameters (4, 12). After a while,
> bang.
>
> I can't say I know what your code is _supposed_ to do, but I'm sure it
> isn't doing it!
>
> Andy

yes, my post was to hasty. the call with (4, 12) will end with the calls
(4, and (8, 12) because of post on 13:07. i will not post some kind
of experimental code in the future anymore.

cheers, chris