fork download
  1. #include <iostream>
  2.  
  3. static void _pass() {}
  4. struct Iman
  5. {
  6. static void salam() {std::cout << "salam";}
  7. };
  8.  
  9. template<typename Class>
  10. struct HasSalam
  11. {
  12. typedef char _1Byte;
  13. typedef struct { char a[2]; } _2Bytes;
  14. template<typename __Class> static _1Byte Check(int __Class::*);
  15. template<typename __Class> static _2Bytes Check(...);
  16. enum { result = sizeof(HasSalam<Class>::Check<Class>(0)) == sizeof(_1Byte) };
  17. };
  18.  
  19. template<bool N> struct IF
  20. {
  21. static constexpr int Result = 1;
  22. template<class A> static void print()
  23. {
  24. A::salam();
  25. }
  26. };
  27. template<> struct IF<false>
  28. {
  29. static constexpr int Result = 0;
  30. template<class A> static void print()
  31. {
  32. _pass();
  33. }
  34. };
  35. template<class T>
  36. struct PrintIfHasSalamMethod
  37. {
  38. static void proceed()
  39. {
  40. IF<
  41. HasSalam<T>::result
  42. >::print<T>();
  43. }
  44. };
  45. int main()
  46. {
  47. PrintIfHasSalamMethod<Iman>::proceed();
  48. }
  49.  
Compilation error #stdin compilation error #stdout 0s 15224KB
stdin
Standard input is empty
compilation info
prog.cpp: In static member function ‘static void PrintIfHasSalamMethod<T>::proceed()’:
prog.cpp:42:13: error: expected primary-expression before ‘>’ token
   >::print<T>();
             ^
prog.cpp:42:15: error: expected primary-expression before ‘)’ token
   >::print<T>();
               ^
stdout

Standard output is empty