fork download
  1. #include <typeinfo>
  2. #include <iostream>
  3.  
  4. template <class T, class U>
  5. struct is_same
  6. {
  7. static const bool value = false;
  8. };
  9.  
  10. template <class T>
  11. struct is_same<T, T>
  12. {
  13. static const bool value = true;
  14. };
  15.  
  16. struct S
  17. {
  18. long a:3;
  19. char b:5;
  20. char c:1;
  21. };
  22.  
  23. template <class T, class U>
  24. void print_is_same(T, U)
  25. {
  26. std::cout << typeid(T).name() << " is " << (is_same<T,U>::value? "" : "not ") << "same as " << typeid(U).name() << std::endl;
  27. }
  28.  
  29. int main()
  30. {
  31. S s;
  32. print_is_same(s.a, s.b);
  33. print_is_same(s.b, s.c);
  34. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
l is not same as c
c is same as c