
On 03/13/09 18:49, David Abrahams wrote:
On Mar 9, 2009, at 10:00 AM, Larry Evans wrote:
Why is there both a ForwardOp and BackwardOp template argument to iter_fold_if?
https://svn.boost.org/trac/boost/browser/trunk/boost/mpl/iter_fold_if.hpp#L6...
I would have thought that only 1 was needed.
Yeah, only one is needed if you are only interested in traversing the list forward (or backward). [snip] Remember that list structures can only be built backwards, and think about the use of inserters and such with the sequence constructing algorithms.
Lists can only be constructed backwards because lists don't have a push_back? IOW, with only a push_front, the lists have to be constructed: push_front < push_front < push_front < list<> , i3 > , i2 > , i1
to create list<i1,i2,i3>? So, a traversal from back to front, (i3->i1), is needed, and, for example, fold<vector<i1,i2,i3>,list<>, push_front<_,_> > would give: list<i3,i2,i1> Instead, to create list<i1,i2,i3> from some sequence, S<i1,i2,i3>, reverse_fold would be needed: reverse_fold<S<i1,i2,i3>,list<>, push_front<_,_> > Is that about what you mean? [snip]
HTH,
Yes. Thank you, David. -regards, Larry