fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. struct UserType{};
  5. struct LibType1{};
  6. struct LibType2{};
  7.  
  8. namespace def {
  9. struct NoOp {};
  10.  
  11. template <typename T>
  12. NoOp operator ^ (T, LibType2)
  13. {
  14. static_assert(sizeof(T) == 0, "Don't do that.");
  15. }
  16. }
  17.  
  18. // try commenting this out
  19. LibType1 operator ^ (UserType, LibType2)
  20. {
  21. return {};
  22. }
  23.  
  24. void doIt(UserType ut)
  25. {
  26. using namespace def;
  27. LibType2 lt2;
  28. ut ^ lt2;
  29. }
  30.  
  31. template <typename T>
  32. bool exists()
  33. {
  34. using namespace def;
  35. return !std::is_same<decltype(std::declval<T>() ^ std::declval<LibType2>()), NoOp>::value;
  36. }
  37.  
  38. int
  39. main(void)
  40. {
  41. std::cout << exists<UserType>() << std::endl;
  42. return 0;
  43. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1