Boost logo

Boost :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2002-11-15 03:12:02


Hi,

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 );
}

fold( sequence s, state st, binary_operator op ) {
   iterator it = s.begin();

   while( it != s.end() )
       st = op( st, *it );
}

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 );
}

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 );
}

Gennadiy.

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


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