[proto] How to convert a constant into a proto terminal?

I fear this could be the first of a stream of feeble questions as I try to provoke Proto into life: As the docs say, "Once we have some Proto terminals, expressions involving those terminals build expression trees for us" ... "As long as one operand is a Proto expression, the result of the operation is a tree node representing that operation". In the calculator example, if I write 10 + 20 + _1 then the 10+20 portion is not a proto expression, which happens to be useful behaviour in this case. But if I wanted to make the 10+20 subexpression a proto expression, I'd need to somehow taint or cast 10. How would I do that? The closest I've spotted in the docs is make_expr(); is this what I need? Phil.

Phil Endecott wrote:
I fear this could be the first of a stream of feeble questions as I try to provoke Proto into life:
No sweat. <snip>
if I wanted to make the 10+20 subexpression a proto expression, I'd need to somehow taint or cast 10. How would I do that?
proto::as_expr() is useful for this. Guess I should say that in the docs, somewhere. -- Eric Niebler Boost Consulting www.boost-consulting.com

Eric Niebler wrote:
Phil Endecott wrote:
if I wanted to make the 10+20 subexpression a proto expression, I'd need to somehow taint or cast 10. How would I do that?
proto::as_expr() is useful for this. Guess I should say that in the docs, somewhere.
I neglected to mention that if you're building a DSEL and you wish "as_expr" were called something else, you can do this: proto::functional::as_expr<> const constant = {}; int main() { constant(10) + 20; return 0; } All of Proto's free functions have function object equivalents in the proto::functional namespace. -- Eric Niebler Boost Consulting www.boost-consulting.com
participants (2)
-
Eric Niebler
-
Phil Endecott