fork download
  1. #include <iostream>
  2. #include <tuple>
  3. #include <iostream>
  4.  
  5. template<class T>
  6. struct X {};
  7.  
  8. template<class T>
  9. bool operator==( X<T>, X<T> ) { return true; }
  10.  
  11. template<class T>
  12. struct Y {
  13. friend bool operator==( Y, Y ) { return true; }
  14. };
  15.  
  16. struct A {
  17. template<class T>
  18. operator X<T>() const { return {}; }
  19. };
  20.  
  21. struct B {
  22. template<class T>
  23. operator Y<T>() const { return {}; }
  24. };
  25.  
  26.  
  27. int main() {
  28. A a;
  29. X<int> x;
  30. B b;
  31. Y<int> y;
  32. b == y;
  33. a == x;
  34. }
  35.  
Compilation error #stdin compilation error #stdout 0s 3292KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:33:4: error: no match for ‘operator==’ (operand types are ‘A’ and ‘X<int>’)
  a == x;
    ^
prog.cpp:33:4: note: candidate is:
prog.cpp:9:6: note: template<class T> bool operator==(X<T>, X<T>)
 bool operator==( X<T>, X<T> ) { return true; }
      ^
prog.cpp:9:6: note:   template argument deduction/substitution failed:
prog.cpp:33:7: note:   ‘A’ is not derived from ‘X<T>’
  a == x;
       ^
stdout
Standard output is empty