Advertisement
frasl

Untitled

Feb 11th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. struct Hello
  4. {
  5.     int helloworld() { return 0; }
  6. };
  7.  
  8. struct Generic {};    
  9.  
  10. // SFINAE test
  11. template <typename T>
  12. class has_helloworld
  13. {
  14.     typedef char one;
  15.     typedef long two;
  16.  
  17.     template <typename C> static one test( typeof(&C::helloworld) ) ;
  18.     template <typename C> static two test(...);    
  19.  
  20. public:
  21.     enum { value = sizeof(test<T>(0)) == sizeof(char) };
  22. };
  23.  
  24. int main(int argc, char *argv[])
  25. {
  26.     std::cout << has_helloworld<Hello>::value << std::endl;
  27.     std::cout << has_helloworld<Generic>::value << std::endl;
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement