
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#L4...
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#L7...
?
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