Boost logo

Boost :

Subject: [boost] [mpl]if_recur vs. iter_fold_if (was Re: [mpl]iter_fold_if Forward Backward rationale?
From: Larry Evans (cppljevans_at_[hidden])
Date: 2009-04-07 20:15:25


On 04/05/09 08:39, Larry Evans wrote:
[snip]
>
> 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

>
>
> ?

The attached code has the template, if_recur, which, AFAICT, is more
general than iter_fold_if. It's more general because it's not "tied"
to sequences. IOW, it's more like a while loop only instead of just
tail recursion, it implements a more general type of "linear"recursion
as described in the reference shown in the comments. The test shows
both the equivalent of the fold and the reverse_fold (the
result_up_push and the result_down_push_). It also shows the
equivalent to the palindrome example of the previous post. Of cousse
it maybe not as efficient as just using fold or reverse_fole; however,
that's just the cost of more generality.

It would be interesting to figure out how to code a sequence of linear
recursive equations. The if_recur is just a single equation. Anybody
care to try?

-regards,
Larry




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