
(Please don't top-post in the future. Thanks.) Kim Kuen Tang wrote:
Hi Eric,
thank you for your quick response.
It is interesting to see that expression like "Domain( [0,1] )" is not allowed. I think the reason is that such expression cannot be transformed in a tree or the transformation is not unique.
No, it is because "Domain( [0,1] )" is disallowed by the grammar for legal C++ expressions. operator[] is binary. You could do this: "Domain( _[0,1] )" but ....
But why does the code "proto::display_expr(Domain[1,2]);" produce the output:
subscript( terminal(domain_tag) ,terminal(2) )
and not
subscript( terminal(domain_tag) ,terminal(1) ,terminal(2) ) ?
... the expression "0,1" already has a meaning in C++. It means, evaluate "0", discard it, evaluate "1". You can only overload operators on user-defined types. HTH,
Eric Niebler schrieb:
Kim Kuen Tang wrote:
Hi all,
i have a question and a problem.
The problem is that i would like to write code like: domain=Domain([0,1]*[0,1]); where Domain([0,1]*[0,1]) is an expression created with proto.
But of course this line of code is illegal, because i have to provide the type of this expression Domain([0,1]*[0,1]).
That line of code is illegal because there is no way to make "Domain([0,1]*[0,1])" a valid C++ expression. You need to work on your syntax a little.
So i have to write something like this: Domain([0,1]*[0,1])::type domain=Domain([0,1]*[0,1]); Is this correct?
Now the question: To avoid code like above is this what the macro BOOST_PROTO_AUTO is for? Can i write BOOST_PROTO_AUTO( domain,Domain([0,1]*[0,1]) ); .
Yes, that is what BOOST_PROTO_AUTO is for.
-- Eric Niebler BoostPro Computing www.boostpro.com