How C++ 11 std::result_of or C++ 17 invoke_result works

306 Views Asked by At

I'm trying to understand C++ metaprogramming and looking at a type_traits header. But I really can't understand, how std::result_of works. A simple version of result_of is not difficult:

template<class...> struct result_of {};
template <class F, typename... Args> struct result_of<F, Args...> {
    using type = decltype(std::declval<F>()(std::declval<Args>()...));
};

and also is not complete. And I feel stupid, when I see gcc, llvm implementations or implementation provided by cppreference. So how it works and why so difficult?

This is not a practical question, it's a theory question. But... I'm really tried to find an explanation.

0

There are 0 best solutions below