On the various ways of getting the result type of a function

Viewed 303

In a context where the type of the result of a function call must be deduced, C++ seems to be more that happy to help us, providing (at least to my knowledge the following) two solutions :

  • The result of type trait :

    std::result_of<F(Args...)>::type
    
  • A core language syntax :

    decltype(std::declval<F>()(std::declval<Args>()...); 
    

My question is, are the any differences between the two? Is there a context where one cannot be substituted by the other and if not why did we need a type trait to do something the language could do out of the box ?

3 Answers
Related