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