Boost logo

Boost :

From: Markus Werle (numerical.simulation_at_[hidden])
Date: 2008-03-11 11:22:40


Eric Niebler <eric <at> boost-consulting.com> writes:
 
> Markus Werle wrote:
> > Hi!
> >
> > In the section "Expression Nodes as Fusion Sequences"
> > you show the follwing code
> >
> > struct fun_t {};
> > terminal<fun_t>::type const fun = {{}};
> >
> > // ...
> > fusion::for_each(
> > fusion::transform(
> > // pop_front() removes the "fun" child
> > fusion::pop_front(fun(1,2,3,4))
> > // Extract the ints from the terminal nodes
> > , functional::arg<>()
> > )
> > , display()
> > );
> >
> >
> > It did not became clear to me why a terminal<fun_t>::type
> > can be initialized with 4 integer arguments.
>
> "fun" is an object. It is already initialized.

I should be careful about how I ask, sorry for the stupid error.
I meant operator call not initialization, but I had in mind that
fun(1, 2, 3, 4) initializes some sort of expr<>, see questions below.

> > I thought terminal<fun_t>::type is equivalent to
> > expr< tag::terminal, args0< fun_t >, 0 >
> > and should take no args at all.
> > Could you clarify this?
>
> "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)

> 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?

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.

> 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.

Markus
 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk