Contains definition of the proto::fold_tree<> and proto::reverse_fold_tree<> transforms. proto::transform< fold_tree<Sequence, State0, Fun> > A PrimitiveTransform that recursively applies the proto::fold<> transform to sub-trees that all share a common tag type. proto::fold_tree<> is useful for flattening trees into lists; for example, you might use proto::fold_tree<> to flatten an expression tree like a | b | c into a Fusion list like cons(c, cons(b, cons(a))). proto::fold_tree<> is easily understood in terms of a recurse_if_<> helper, defined as follows: template<typename Tag, typename Fun> struct recurse_if_ : proto::if_< // If the current node has type type "Tag" ... boost::is_same<proto::tag_of<proto::_>, Tag>(), // ... recurse, otherwise ... proto::fold<proto::_, proto::_state, recurse_if_<Tag, Fun> >, // ... apply the Fun transform. Fun > {}; With recurse_if_<> as defined above, proto::fold_tree<Sequence, State0, Fun>()(expr, state, data) is equivalent to: proto::fold< Sequence, State0, recurse_if_<typename Expr::proto_tag, Fun> >()(expr, state, data). It has the effect of folding a tree front-to-back, recursing into child nodes that share a tag type with the parent node. proto::fold<Sequence, State0, recurse_if_<typename Expr::proto_tag, Fun> > ::template impl<Expr, State, Data> proto::transform< reverse_fold_tree<Sequence, State0, Fun> > A PrimitiveTransform that recursively applies the proto::reverse_fold<> transform to sub-trees that all share a common tag type. proto::reverse_fold_tree<> is useful for flattening trees into lists; for example, you might use proto::reverse_fold_tree<> to flatten an expression tree like a | b | c into a Fusion list like cons(a, cons(b, cons(c))). proto::reverse_fold_tree<> is easily understood in terms of a recurse_if_<> helper, defined as follows: template<typename Tag, typename Fun> struct recurse_if_ : proto::if_< // If the current node has type type "Tag" ... boost::is_same<proto::tag_of<proto::_>, Tag>(), // ... recurse, otherwise ... proto::reverse_fold<proto::_, proto::_state, recurse_if_<Tag, Fun> >, // ... apply the Fun transform. Fun > {}; With recurse_if_<> as defined above, proto::reverse_fold_tree<Sequence, State0, Fun>()(expr, state, data) is equivalent to: proto::reverse_fold< Sequence, State0, recurse_if_<typename Expr::proto_tag, Fun> >()(expr, state, data). It has the effect of folding a tree back-to-front, recursing into child nodes that share a tag type with the parent node. proto::reverse_fold<Sequence, State0, recurse_if_<typename Expr::proto_tag, Fun> > ::template impl<Expr, State, Data>