Advertisement
ComradePetr

contains_foo_type

May 28th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. template<class T>
  5. struct contains_foo_type{
  6.     typedef int true_type;
  7.     typedef char false_type;
  8.     template<class S>
  9.     static true_type f(typename S::foo_type* a);
  10.     template<class S>
  11.     static false_type f(...);
  12.     static const bool value=sizeof(f<T>(0))==sizeof(true_type);
  13. };
  14.  
  15. struct A{};
  16. struct B{typedef int foo_type;};
  17. struct C{int foo_type;};
  18.  
  19. int main(){
  20.     printf("%d\n",contains_foo_type<A>::value);
  21.     printf("%d\n",contains_foo_type<B>::value);
  22.     printf("%d\n",contains_foo_type<C>::value);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement