fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. struct NoComparable {
  6. };
  7.  
  8. struct ComparableWithItself {
  9. };
  10.  
  11. bool operator == (ComparableWithItself const &lhs, ComparableWithItself const &rhs) {
  12. return true;
  13. }
  14.  
  15. struct ComparableWithItselfAndOther {
  16. bool operator == (ComparableWithItselfAndOther const &lhs) const {
  17. return true;
  18. }
  19.  
  20. bool operator == (ComparableWithItself const &lhs) const {
  21. return true;
  22. }
  23. };
  24.  
  25. namespace CHECK // namespace to let "operator ==" not become global
  26. {
  27. typedef char no[7];
  28. template<typename T, typename T2> no& operator == (const T&, const T2&);
  29.  
  30. template <typename T, typename T2>
  31. struct opEqualExists // *(T*)(0) can be replaced by *new T[1] also
  32. {
  33. enum { value = (sizeof(*(T*)(0) == *(T2*)(0)) != sizeof(no)) };
  34. };
  35. }
  36.  
  37.  
  38. int main() {
  39. std::cout << CHECK::opEqualExists<ComparableWithItselfAndOther, ComparableWithItselfAndOther>::value << std::endl;
  40. std::cout << CHECK::opEqualExists<ComparableWithItself, ComparableWithItself>::value << std::endl;
  41. std::cout << CHECK::opEqualExists<ComparableWithItselfAndOther, ComparableWithItself>::value << std::endl;
  42. std::cout << CHECK::opEqualExists<ComparableWithItself, ComparableWithItselfAndOther>::value << std::endl;
  43. std::cout << CHECK::opEqualExists<NoComparable, NoComparable>::value << std::endl;
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 2684KB
stdin
Standard input is empty
stdout
1
1
1
0
0