fork(1) download
  1.  
  2.  
  3. #include<iostream>
  4. #include<type_traits>
  5.  
  6. struct A{};
  7. struct B{};
  8. struct C{};
  9.  
  10.  
  11.  
  12. template <typename ... Args>
  13. struct Convert;
  14.  
  15. template <typename T>
  16. struct Convert<T,T> {
  17.  
  18. static int param() { return 0; }
  19. };
  20.  
  21. template <typename T, typename U>
  22. struct Convert<T,U> {
  23.  
  24. static decltype(-Convert<U,T>::param()) param() { return -Convert<U,T>::param(); }
  25. };
  26.  
  27. template <>
  28. struct Convert<A,B> {
  29. static int param() { return 42; }
  30. };
  31.  
  32. template <>
  33. struct Convert<A,C> {
  34. static int param() { return 43; }
  35. };
  36.  
  37. template <>
  38. struct Convert<B,C> {
  39. static int param() { return 44; }
  40. };
  41.  
  42. int main()
  43. {
  44. std::cout<<Convert<A,B>::param()<<std::endl;
  45. std::cout<<Convert<B,A>::param()<<std::endl;
  46. std::cout<<Convert<A,C>::param()<<std::endl;
  47. std::cout<<Convert<C,A>::param()<<std::endl;
  48. std::cout<<Convert<B,C>::param()<<std::endl;
  49. std::cout<<Convert<C,B>::param()<<std::endl;
  50.  
  51. Convert<int,double>::param();
  52. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘struct Convert<double, int>’:
prog.cpp:24:42:   required from ‘struct Convert<int, double>’
prog.cpp:51:24:   required from here
prog.cpp:24:42: error: incomplete type ‘Convert<int, double>’ used in nested name specifier
     static decltype(-Convert<U,T>::param()) param() { return -Convert<U,T>::param(); }
                                          ^
prog.cpp: In instantiation of ‘struct Convert<int, double>’:
prog.cpp:51:24:   required from here
prog.cpp:24:42: error: ‘param’ is not a member of ‘Convert<double, int>’
prog.cpp: In function ‘int main()’:
prog.cpp:51:5: error: ‘param’ is not a member of ‘Convert<int, double>’
     Convert<int,double>::param();
     ^
stdout
Standard output is empty