Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2008-03-11 11:40:41

Markus Werle wrote:
> Eric Niebler <eric <at>> writes:
>> "fun(1,2,3,4)" is an invocation of an overloaded function call operator.
> OK, for me it was not clear from the docs why fun is a function object
> (or similar thing) that takes 4 arguments - or more.
> Up to this point in the docs no operator() was mentioned (or I overlooked it)

"fun" is a node in an expression tree. Proto overloads *all* operators
for Proto expressions. So you can say "fun + fun" and build a new node
representing an addition. Or you can say "fun(fun)" to build a new node
representing a function call. You could even say "(fun + fun)(fun, fun
fun)". But that would be too much fun. :-)

>> Proto is an expression template library ... all operators are overloaded
>> to build expression trees.
> Now since my reputation is lost anyway, let's go on
> asking further stupid questions:
> 1. fun is of type expr< tag::terminal, args0< fun_t >, 0 > - right?


> 2. a terminal expression like "fun" has a set of overloaded
> operators for an arbitrary number of operators (until some
> PROTO_MAX_SIZE_WHATEVER) that returns a fusion compatible sequence?

Yes, up to BOOST_PROTO_MAX_ARITY operands.

> 3.For me a terminal is a "do-nothing", a holder.
> I get confused now. Here the terminal has some magic behind the scenes
> which I would not expect at this place. A terminal with arity 0 takes
> 4 arguments. I do not get that into my thick skull.

It's just an overloaded function call operator. All Proto expression
types, terminals and non-terminals, have them.

>> This operator builds a tree node representing
>> a function invocation.
> What is the resulting type of the function call fun(1, 2, 3, 4)?
> I would have expected to see "whatever(1, 2, 3, 4)" be represented
> as expr<tag::noop, args4<int, int, int, int> >.
> Now I read this like the function call itself is stored as a NOOP-leaf
> with 4 arguments ... getting lost.

The type of "fun(1,2,3,4)" would look something like:

     ref_<expr<tag::terminal, args0<fun_tag> > const>
    ,expr<tag::terminal, args0<int const &> >
    ,expr<tag::terminal, args0<int const &> >
    ,expr<tag::terminal, args0<int const &> >
    ,expr<tag::terminal, args0<int const &> >


Eric Niebler
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at