Difference between std::result_of and decltype

后端 未结 2 1453

I have some trouble understanding the need for std::result_of in C++0x. If I understood correctly, result_of is used to obtain the resulting type o

2条回答
  •  既然无缘
    2020-11-29 17:33

    result_of was introduced in Boost, and then included in TR1, and finally in C++0x. Therefore result_of has an advantage that is backward-compatible (with a suitable library).

    decltype is an entirely new thing in C++0x, does not restrict only to return type of a function, and is a language feature.


    Anyway, on gcc 4.5, result_of is implemented in terms of decltype:

      template
        class result_of;
    
      template
        struct result_of<_Functor(_ArgTypes...)>
        {
          typedef
            decltype( std::declval<_Functor>()(std::declval<_ArgTypes>()...) )
            type;
        };
    

提交回复
热议问题