
On 03/17/08 16:35, Markus Werle wrote:
Hi!
Sorry, Eric, if this is a lot of work. Reject to do it, if you like, or provide only some of these.
---- Task 1 -------------- Consider I need to flatten a tree into a sum:
template<int I> struct arg {};
proto::terminal<arg<1> >::type a; proto::terminal<arg<2> >::type b; proto::terminal<arg<3> >::type c; proto::terminal<arg<4> >::type d;
a + b + c + d
has type expr<tag::plus, arg2<a tree structure> >
but I need a template function make_flat taking arbitray expressions and return expressions of type
expr<sum, args4<all args in the typelist> >
How can I do this in proto?
----------- Task 2: Next step:
a - b + c should first be transformed into a + (-b) + c and then transformed into the sum.
Could you please provide full compilable examples?
------
Task 3: Next step:
I want to detect simultaneous occurences of x and -x and have them dropped from the typelist of my sum. Please provide an example that detects this for terminals only, then one which also works for (a*b - a*b) and returns expr<tag::nil, nulllist> (BTW, is there a nil/null tag in proto?)
---------
Task 4: Write an expand function that for a*(b+c) returns a type representation a*b+a*c
-----
Me too! In general, there should be an n-ary version of all the binary ops. This should also be extended to the or_ also. I remember having a problem with folding or_ because it was an n-ary op and had to define my own binary or which just forwarded to the or_. That was a "kludge". So maybe define or_ as binary and then define the n-ary version based on this binary.