Boost logo

Boost :

Subject: Re: [boost] [mpl]iter_fold_if Forward Backward rationale?
From: Larry Evans (cppljevans_at_[hidden])
Date: 2009-04-05 09:39:51


On 04/04/09 12:41, Larry Evans wrote:
[snip]
>
> Now, if B==F==push_front, this would produce a palindrome:
>
> [x1,x2,x3,x3,x2,x1]
>
> This is demonstrated by the attached program which produces on cout:
>
> ***test_iter_fold_if<1> numbers=:
> value:0
> ***test_iter_fold_if<1> result::state=:
> r_iter:0
> r_iter:1
> r_iter:1
> r_iter:1
> r_iter:0
[snip]
>
> However, I 've not figured out where the extra number (1 in case of
> iter_fold_if<1> and 2 in case of iter_fold_if<2>) is coming from.
> OTOH, I haven't tried very hard to figure it out.

The previous attachment should have had:

   push_front<arg<1>,deref<arg<2> > >

instead of:

   push_front<arg<1>,arg<2> >

as both the ForwardOp and BackwardOp. Also, the
BackwardPredicate should have been:

    protect
    < aux::iter_fold_if_pred
      < always<true_>
      , typename end<numbers>::type
>
>

With those changes, the correct palindrome is produced.

Just as the ForwardPredicate is "augmented" with protection
against dereferencing the end<numbers>::type in this code:

https://svn.boost.org/trac/boost/browser/trunk/boost/mpl/iter_fold_if.hpp#L42

shouldn't the BackwardPredicate also be augmented with the same
protection here:

https://svn.boost.org/trac/boost/browser/trunk/boost/mpl/iter_fold_if.hpp#L77

?

-regards,
Larry

the B


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