开发者

C++, what does this syntax mean?

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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜