Advertisement
Guest User

metafunction

a guest
Dec 13th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. using YES = char;
  5. struct NO { YES m[2]; };
  6.  
  7. template<typename T>
  8. struct Method {};
  9.  
  10. template<>
  11. struct Method<int> {
  12.   void func() {};
  13. };
  14.  
  15. template<typename T>
  16. struct is_func_defined {
  17.   Method<T> m;
  18.     template<class Z, std::function<void()> = &(m.func)>
  19.     struct wrapper {};
  20.  
  21.     template<class C>
  22.     static YES check(wrapper<C> * p);
  23.  
  24.     template<class C>
  25.     static NO check(...);
  26.  
  27.     static bool const value = sizeof(YES) == sizeof(check<T>(0));
  28. };
  29.  
  30. int main() {
  31.   std::cout << is_func_defined<int>::value << std::endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement