Hi all,
i want to use the function proto::reverse_fold_tree to build a
heterogeneous list from the expression "((a*b+c)*d+e)*f". The resulting
sequence only contains the two terminals 'a' and b'. So i am a little
bit confused.
But using the function proto::fold_tree it produces correctly the
sequence [f,e,d,c,b,a]. (Btw the two functions proto::fold_tree and
proto::fold produce the same sequence [f,e,d,c,b,a], what is their
difference? )
Here is the code:
#include <iostream>
#include
#include
#include
#include
#include
#include
namespace mpl = boost::mpl;
namespace proto = boost::proto;
namespace fusion = boost::fusion;
using proto::_;
proto::terminal<char>::type const a = {'a'};
proto::terminal<char>::type const b = {'b'};
proto::terminal<char>::type const c = {'c'};
proto::terminal<char>::type const d = {'d'};
proto::terminal<char>::type const e = {'e'};
proto::terminal<char>::type const f = {'f'};
struct FoldToList
: proto::or_<
proto::when,fusion::cons(proto::_value, proto::_state) >
,proto::when >,
proto::fold_tree >
>
{};
struct FoldToListReverse
: proto::or_<
proto::when,fusion::cons(proto::_value, proto::_state) >
,proto::when >,
proto::reverse_fold_tree >
>
{};
struct print
{
typedef void result_type;
template<class T>
result_type
operator()(T const& t) const
{
std::cout<));
BOOST_MPL_ASSERT(( proto::matches));
BOOST_AUTO(sequence1,FoldToList()(expr));
fusion::for_each(sequence1,print());
std::cout << "\n--------------------\n";
BOOST_AUTO(sequence2,FoldToListReverse()(expr));
fusion::for_each(sequence2,print());
std::cout << "\n--------------------\n";
}
Cheers
Kim Tang