Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-11-15 08:05:01


Gennadiy Rozental wrote:
> Would it correct to state that following pseudo-code properly
> reflect the essence of the appropriate algorithms:
>
> iter_fold( sequence s, state st, binary_operator op ) {
> iterator it = s.begin();
>
> while( it != s.end() )
> st = op( st, it );

    return st;
> }

> fold( sequence s, state st, binary_operator op ) {
> iterator it = s.begin();
>
> while( it != s.end() )
> st = op( st, *it );

    return st;
> }

> iter_fold_backward( sequence s,
> state st,
> binary_operator backward_op,
> binary_operator forward_op = identity ) {
> iterator it = s.begin();
>
> while( it != s.end() )
> st = forward_op( st, it );
>
> while( --it != s.begin() )
> st = forward_op( st, it );
>
> st = forward_op( st, it );

    return st;
> }

>
> fold_backward( sequence s,
> state st,
> binary_operator backward_op,
> binary_operator forward_op = identity ) {
> iterator it = s.begin();
>
> while( it != s.end() )
> st = forward_op( st, *it );
>
> while( --it != s.begin() )
> st = forward_op( st, *it );
>
> st = forward_op( st, *it );

    return st;
> }

Yep, that's basically what they do.

> P.S. MPL docs reference pages does not formatted for
> printing. They does not fit the page width. See iter_fold or example.

Yep, it's a known problem. The new revision will come in PDF (properly
formatted) as well as HTML, so it won't be an issue then.

Aleksey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk