Quick Q: What's the difference between result_of and decltype? -- StackOverflow

From SO:

What's the difference between result_of<F(Args…> and decltype<f(args…)>?

I see that std::async is specified as follows:

template <class F, class... Args>                   // copied out of the standard
future<typename result_of<F(Args...)>::type>
async(F&& f, Args&&... args);

I had expected it to be declared like this:

template <class F, class... Args>
auto async(F&& f, Args&&... args) ->
  future<decltype(f(forward<Args>(args)...)>;

Would that be equivalent, or is there some way in which the use of result_of is preferable to the use of decltype? (I understand that result_of works with types, while decltype works with expressions.)

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.