tags:

views:

121

answers:

2

i found this in this file: http://www.boost.org/doc/libs/1_43_0/boost/spirit/home/phoenix/core/actor.hpp

What does this syntax means?

struct actor ... {
        ...
        template <typename T0, typename T1>
        typename result<actor(T0&,T1&)>::type // this line

I know what typename and templates are, my question is about actor(T0&,T1&) syntax

thank you

+2  A: 

So this means that there is a template called result and within result is a type called type.

template <class T>
class result
{
public:
    typedef ... type;
};

So that line is using that type from the template.

Because the compiler does not know what result<actor(T0&,T1&)>::type is, you need to use typename to tell the compiler to treat it as a type.

Update

actor(T0&,T1&) is a function taking a T0& and a T1& and returning an actor by value.

R Samuel Klatchko
aaa
@aaa - a function taking a `T0` and `T1` both by reference and returning an `actor` by value.
R Samuel Klatchko
thank you.I am actually somewhat familiar with function/function pointer syntax, but I have never seen it as template parameter.
aaa
@aaa to clarify, it's not somehow a function *call* (as it looks quite similar), but it's the *type* of a function.
Johannes Schaub - litb
+3  A: 

The full declaration from that file reads:

template <typename T0, typename T1>
typename result<actor(T0&,T1&)>::type
operator()(T0& _0, T1& _1) const
{
    /* snip */
}

If you break it down into chunks, it's easier to read:

template <typename T0, typename T1>

It's a template...

operator()(...) const

...a templated function-call operator function...

operator()(T0& _0, T1& _1) const

...which takes two arguments, by reference, of type T0 and T1...

typename result<...>::type

...and returns a result whose type is the type member of result...

typename result<actor(T0&,T1&)>::type

...where the type of result is paramaterised by the expression actor(T0&,T1&).

Blair Holloway