fork(6) download
  1. #include<iostream>
  2.  
  3. namespace CHECK
  4. {
  5. class No { bool b[2]; };
  6. template<typename T, typename Arg> No operator== (const T&, const Arg&);
  7.  
  8. bool Check (...);
  9. No& Check (const No&);
  10.  
  11. template <typename T, typename Arg = T>
  12. struct EqualExists
  13. {
  14. enum { value = (sizeof(Check(*(T*)(0) == *(Arg*)(0))) != sizeof(No)) };
  15. };
  16. }
  17.  
  18.  
  19. struct A
  20. {
  21. bool operator == (A const &);
  22. };
  23.  
  24. struct B
  25. {
  26. short operator == (B const &);
  27. };
  28.  
  29. struct C {};
  30.  
  31. struct D
  32. {
  33. short operator == (short);
  34. };
  35.  
  36. int main()
  37. {
  38. std::cout<< "A::operator== () exists: " << CHECK::EqualExists<A>::value << std::endl;
  39. std::cout<< "B::operator== () exists: " << CHECK::EqualExists<B>::value << std::endl;
  40. std::cout<< "C::operator== () exists: " << CHECK::EqualExists<C>::value << std::endl;
  41. std::cout<< "C::operator== (short) exists: " << CHECK::EqualExists<D, short>::value << std::endl;
  42. }
  43.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
A::operator== () exists: 1
B::operator== () exists: 1
C::operator== () exists: 0
C::operator== (short) exists: 1