fork download
  1. #include <type_traits>
  2. #include <utility>
  3. #include <iostream>
  4.  
  5. class Foo {
  6. public:
  7. int print(int a, double b){ std::cout<<"Foo::print(int,double)";}
  8. int print(int a);
  9. };
  10. template <class MT>
  11. struct method_info;
  12.  
  13. template <class T, class Res, class... Args>
  14. struct method_info<Res(T::*)(Args...)>
  15. {
  16. typedef std::tuple<Args&&...> args_tuple;
  17. typedef T ClassType;
  18. typedef Res RetVal;
  19. };
  20.  
  21. int fooprint2(int a, double b);
  22.  
  23. template <class MethodType>
  24. void func() {
  25. typedef method_info<MethodType> MethodInfo;
  26. std::cout<<"func<MethodType>()";
  27. }
  28.  
  29. template<typename ... Args>
  30. //using print_type = decltype(std::declval<Foo>().print(std::declval<Args>() ...)) (Foo::*)(Args ...); //version1 (std::declval) = OK
  31. using print_type = std::result_of_t<decltype(&Foo::print)(Foo, Args ...)> (Foo::*)(Args ...); //version2 (std::result_of) = not work
  32.  
  33. int main(){
  34. func<print_type<int,double> >();
  35. }
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp:31:57: error: decltype cannot resolve address of overloaded function
 using print_type = std::result_of_t<decltype(&Foo::print)(Foo, Args ...)> (Foo::*)(Args ...);        //version2 (std::result_of) = not work
                                                         ^
prog.cpp:31:73: error: template argument 1 is invalid
 using print_type = std::result_of_t<decltype(&Foo::print)(Foo, Args ...)> (Foo::*)(Args ...);        //version2 (std::result_of) = not work
                                                                         ^
prog.cpp: In function ‘int main()’:
prog.cpp:34:10: error: ‘print_type’ was not declared in this scope
     func<print_type<int,double> >();
          ^~~~~~~~~~
prog.cpp:34:5: error: parse error in template argument list
     func<print_type<int,double> >();
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:34:35: error: expected primary-expression before ‘)’ token
     func<print_type<int,double> >();
                                   ^
stdout
Standard output is empty