随笔 - 64, 文章 - 11, 评论 - 12, 引用 - 0
数据加载中……

c++0x 系列

result_of 用于推导可调用对象的返回类型。
大致定义:
template<class Ty>
    struct result_of {
    typedef T0 type;
    };
Ty: 可调用类型,

The template class defines its member type as a synonym for the return type of a function call described by its template argument Ty. The template argument must be of the form Fty(T1, T2, ..., TN), where Fty is a callable type. The template determines the return type according to the first of the following rules that applies:

  • if Fty is a pointer to function type R(*)(U1, U2, ..., UN) the return type is R;

  • 如果Fty是个R(*)(U1, U2, ..., UN) 函数指针,那么返回类型是R

  • if Fty is a reference to function type R(&)(U1, U2, ..., UN) the return type is R;

  • 如果Fty是个R(&)(U1, U2, ..., UN) 函数指针,那么返回类型是R

  • if Fty is a pointer to member function type R(U1::*)(U2, ..., UN) the return type is R;

  • 如果Fty是个R(U1::*)(U2, ..., UN)成员函数指针,那么返回类型是R

  • if Fty is a pointer to data member type R U1::* the return type is R;

  • 如果Fty是个R U1::* 成员变量指针,那么返回类型是R

  • if Fty is a class with a member typedef result_type the return type is Fty::result_type;

  • 如果Fty是一个类并且其中定义了result_type ,那么返回类型是Fty::result_type

  • if N is 0 (that is, Ty is of the form Fty()) the return type is void;

  • 如果Fty函数不带有任何的参数,那么返回类型是void

  • if Fty is a class with a member template named result the return type is Fty::result<T1, T2, ..., TN>::type;

  • 如果Fty是个类并且有个成员模板是result,那么返回类型是Fty::result<T1, T2, ..., TN>::type

  • in all other cases it is an error.

  • 其它情况就会出错

posted on 2011-07-29 10:24 Robertxiao 阅读(149) 评论(0)  编辑 收藏 引用 所属分类: C++ Tech


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理